4 * URL: http://d.hatena.ne.jp/uupaa/20080413/1208067631
\r
5 * AUTHOR: uupaa.js@gmail.com
\r
9 var X_Net_Image_hasImage = !!window[ 'Image' ],
\r
10 X_Net_Image_image = X_Net_Image_hasImage && new Image(),
\r
11 // IE では厳密には HTMLImageElement ではなく、appendChild してもサイズが取れず、removeChild に失敗する
\r
12 X_Net_Image_isElement = !( X_UA.IE < 9 ) && X.Type.isHTMLElement( X_Net_Image_image );
\r
15 if( !X_Net_Image_hasImage ){
\r
16 alert( 'no Image!' );
\r
18 if( X_Net_Image_isElement ){
\r
19 //alert( 'X_Net_Image_isElement ' + X_Net_Image_isElement );
\r
24 * new Image() のときに Image オブジェクトを作るもの(IE8-)と、HTMLImageElement を作るものがある。
\r
25 * Image は、X.EventDispatcher で、<img> は X.Node で。
\r
27 * Opera7 では毎回 image を作る必要あり、src が異なればOK?
\r
29 X_NET_ImageWrapper = X_Class_override(
\r
30 !X_Net_Image_isElement ? new X.EventDispatcher( X_Net_Image_image ) : new X.Node( X_Net_Image_image ),
\r
41 load : function( data ){
\r
43 this.abspath = X.URL.toAbsolutePath( data.url );
\r
44 this.delay = data.delay || 100;
\r
45 this.timeout = data.timeout || 5000;
\r
46 //this.timerID = X.Timer.add( this.delay, 0, this, this._detect );
\r
48 this._rawObject.src = this.abspath;
\r
50 if( X_UA.Opera7 && this._rawObject.complete ){
\r
51 this.asyncDispatch( 'load' );
\r
53 this.timerID = X.Timer.add( this.delay, 0, this, this._detect );
\r
57 handleEvent : function( e ){
\r
61 //case 'abort' : // TODO ??
\r
62 if( this.finish ) return;
\r
65 this.timerID && X.Timer.remove( this.timerID );
\r
66 this.timerID = this.asyncDispatch( /*e.type === 'error' ?*/ X.Event.ERROR /*: X.Event.CANCELED*/ );
\r
69 // if( finish === true ) return; // これがあると firefox3.6 で駄目、、、
\r
70 // if( timer ) return; // これがあると safari3.2 で駄目、、、
\r
73 this.timerID && X.Timer.remove( this.timerID );
\r
74 if( X_UA.Opera && !this._rawObject.complete ){
\r
75 this.timerID = this.asyncDispatch( X.Event.ERROR );
\r
78 size = X.Util.Image.getActualDimension( !X_Net_Image_isElement ? this.abspath : this );
\r
79 this.timerID = this.asyncDispatch( {
\r
80 type : X.Event.SUCCESS,
\r
86 case X.Event.KILL_INSTANCE :
\r
88 !X_Net_Image_hasImage && this.destroy(); // if xnode
\r
93 _detect : function(){
\r
94 if( this.finish ) return;
\r
95 if( this._rawObject && this._rawObject.complete ){
\r
98 if( this._rawObject.width ) return;
\r
99 X.Timer.remove( this.timerID );
\r
100 this.timerID = this.asyncDispatch( X.Event.ERROR );
\r
102 if( this.timeout < ( this.tick += this.delay ) ){
\r
103 this._busy = false;
\r
104 this.finish = true;
\r
105 X.Timer.remove( this.timerID );
\r
106 this.timerID = this.asyncDispatch( X.Event.TIMEOUT );
\r
110 cancel : function(){
\r
112 this._rawObject && this._rawObject.abort && this._rawObject.abort();
\r
113 // this._rawObject.src = '';
\r
114 this._busy = false;
\r
115 this.finish = true;
\r
116 this.asyncDispatch( X.Event.CANCELED );
\r
119 reset : function(){
\r
120 this.timerID && X.Timer.remove( this.timerID );
\r
121 //X_Net_Image_isElement ? this._rawObject.removeAttribute( 'src' ) : ( this._rawObject.src = '' );
\r
122 this._rawObject.src = '';
\r
124 this._busy = false;
\r
125 this.finished = false;
\r
131 X_NET_ImageWrapper.listen( [ 'load', 'error' /*, 'abort'*/, X.Event.KILL_INSTANCE ] );
\r
133 // X_Net_Image_isElement && X_NET_ImageWrapper.appendTo( X.X_Node_systemNode );
\r