X-Git-Url: http://git.osdn.jp/view?p=pettanr%2FclientJs.git;a=blobdiff_plain;f=0.6.x%2Fjs%2F06_net%2F04_XNetImage.js;fp=0.6.x%2Fjs%2F06_net%2F04_XNetImage.js;h=3bcc3b8f66073cde781a577e73310448a21138ad;hp=92044e12fd5d8f9beac28406a50c08ef0cff80fc;hb=2bea17ee282c2cf4ce0de6685db3ade602f6e60f;hpb=76ea1040608829b653422cf51b3490801d2ec1fa diff --git a/0.6.x/js/06_net/04_XNetImage.js b/0.6.x/js/06_net/04_XNetImage.js index 92044e1..3bcc3b8 100644 --- a/0.6.x/js/06_net/04_XNetImage.js +++ b/0.6.x/js/06_net/04_XNetImage.js @@ -6,10 +6,12 @@ * AUTHOR: uupaa.js@gmail.com * */ -var X_ImgLoader_hasImage = !!window[ 'Image' ], - X_ImgLoader_image = X_ImgLoader_hasImage && new Image(), +var X_ImgLoader_image = window[ 'Image' ] && new Image(), // IE では厳密には HTMLImageElement ではなく、appendChild してもサイズが取れず、removeChild に失敗する - X_ImgLoader_isElement = !( X_UA[ 'IE' ] < 9 ) && X_Type_isHTMLElement( X_ImgLoader_image ); + X_ImgLoader_isElement = !( X_UA[ 'IE' ] < 9 ) && X_Type_isHTMLElement( X_ImgLoader_image ), + // http://uupaa.hatenablog.com/entry/2013/12/17/171809 + // お手軽に画像の読み込みをハンドリングする、今どきな方法 + X_ImgLoader_0forError = !X_UA[ 'IE' ] || X_UA[ 'IE' ] === 11; /* * TODO @@ -23,16 +25,15 @@ X_TEMP.X_ImgLoader_init = function(){ X_TEMP.X_ImgLoader_params ); - X_ImgLoader[ 'listen' ]( [ 'load', 'error' /*, 'abort'*/, X_EVENT_KILL_INSTANCE ], X_ImgLoader_handleEvent ); + X_ImgLoader[ 'listen' ]( [ 'load', 'error' /*, 'abort'*/ ], X_ImgLoader_handleEvent ); delete X_TEMP.X_ImgLoader_init; - delete X_TEMP.X_ImgLoader_params; + delete X_TEMP.X_ImgLoader_params; return X_ImgLoader; }; X_TEMP.X_ImgLoader_params = { - _busy : false, tick : 0, timerID : 0, finish : false, @@ -41,7 +42,6 @@ X_TEMP.X_ImgLoader_params = { timeout : 0, load : function( data ){ - this._busy = true; this.abspath = X_URL_toAbsolutePath( data[ 'url' ] ); this.delay = data[ 'delay' ] || 100; this.timeout = data[ 'timeout' ] || 5000; @@ -60,7 +60,6 @@ X_TEMP.X_ImgLoader_params = { // abort がある? raw && raw.abort && raw.abort(); // this[ '_rawObject' ].src = ''; - this._busy = false; this.finish = true; }, @@ -68,12 +67,12 @@ X_TEMP.X_ImgLoader_params = { console.log( 'X.Net.Image:reset ' + this.abspath + ' timerID:' + this.timerID ); this.timerID && X_Timer_remove( this.timerID ); + this.timerID = 0; + //X_ImgLoader_isElement ? this[ '_rawObject' ].removeAttribute( 'src' ) : ( this[ '_rawObject' ].src = '' ); this[ '_rawObject' ].src = ''; - this.timerID = 0; - this._busy = false; - this.finished = false; - this.abspath = ''; + this.finish = false; + this.abspath = ''; } }; @@ -81,8 +80,8 @@ function X_ImgLoader_detect(){ var raw = this[ '_rawObject' ]; if( this.finish ) return; + if( raw && raw.complete ){ - this._busy = false; this.finish = true; console.log( 'X.Net.Image:detect ' + raw.width ); if( raw.width ) return; @@ -90,7 +89,6 @@ function X_ImgLoader_detect(){ this.timerID = this[ 'asyncDispatch' ]( X_EVENT_ERROR ); } else if( this.timeout < ( this.tick += this.delay ) ){ - this._busy = false; this.finish = true; X_Timer_remove( this.timerID ); this.timerID = this[ 'asyncDispatch' ]( { type : X_EVENT_ERROR, 'timeout' : true } ); @@ -98,15 +96,18 @@ function X_ImgLoader_detect(){ }; function X_ImgLoader_handleEvent( e ){ - var size; + var raw = this[ '_rawObject' ], size; + // IE11 reset() 時にここに入ってくる... + if( !this.abspath ) return; console.log( 'X.Net.Image:handleEvent ' + e.type ); switch( e.type ){ case 'error' : //case 'abort' : // TODO ?? + // ie11(10,9 開発モード)で mineType 不正の場合、画像取得に成功してもエラーイベントが起こるのを無視する。 + if( X_ImgLoader_0forError && raw.width ) return; if( this.finish ) return; - this._busy = false; this.finish = true; this.timerID && X_Timer_remove( this.timerID ); this.timerID = this[ 'asyncDispatch' ]( /*e.type === 'error' ?*/ X_EVENT_ERROR /*: X_EVENT_CANCELED*/ ); @@ -115,10 +116,9 @@ function X_ImgLoader_handleEvent( e ){ case 'load' : // if( finish === true ) return; // これがあると firefox3.6 で駄目、、、 // if( timer ) return; // これがあると safari3.2 で駄目、、、 - this._busy = false; this.finish = true; this.timerID && X_Timer_remove( this.timerID ); - if( X_UA[ 'Opera' ] && !this[ '_rawObject' ].complete ){ + if( X_UA[ 'Opera' ] && !raw.complete ){ this.timerID = this[ 'asyncDispatch' ]( X_EVENT_ERROR ); return; }; @@ -133,10 +133,6 @@ function X_ImgLoader_handleEvent( e ){ // time , this[ '_rawObject' ].fileSize } ); break; - - case X_EVENT_KILL_INSTANCE : - this.reset(); - break; }; };