8 * AUTHOR: uupaa.js@gmail.com
\r
10 getActualDimension : function( XnodeOrImageElemOrSrc ){
\r
11 var xnode, img, remove, ret, run, memW, memH, w, h;
\r
13 if( X.Type.isString( XnodeOrImageElemOrSrc ) ){
\r
14 if( ret = X.Dom.Image._actualSize[ X.Dom.getAbsolutePath( XnodeOrImageElemOrSrc ) ] ) return ret;
\r
16 xnode = X.Dom.Node._systemNode.create(
\r
19 src : XnodeOrImageElemOrSrc
\r
22 position : 'absolute'
\r
25 Node.root._startUpdate();
\r
26 img = xnode._ie4getRawNode ? xnode._ie4getRawNode() : xnode._rawNode;
\r
29 if( XnodeOrImageElemOrSrc.constructor === X.Dom.Node ){
\r
30 xnode = XnodeOrImageElemOrSrc;
\r
31 img = xnode._ie4getRawNode ? xnode._ie4getRawNode() : xnode._rawNode;
\r
33 if( X.Type.isHTMLElement( XnodeOrImageElemOrSrc ) ){
\r
34 img = XnodeOrImageElemOrSrc;
\r
38 if( ret = X.Dom.Image._actualSize[ img.src ] ) return ret;
\r
41 // for Firefox, Safari, Google Chrome
\r
42 if( img.naturalWidth ) return [ img.naturalWidth, img.naturalHeight ];
\r
44 if( X.UA.IE && 5 <= X.UA.IE ){// for IE
\r
45 run = img.runtimeStyle;
\r
49 // keep runtimeStyle
\r
52 run.height = 'auto';
\r
58 } else {// for Opera and Other
\r
60 memW = w = img.width;
\r
61 memH = h = img.height;
\r
63 if( img.removeAttribute ){ // Safari1.3 の Image は removeAttribute がない
\r
64 // keep current style
\r
65 img.removeAttribute( 'width' );
\r
66 img.removeAttribute( 'height' );
\r
77 ret = X.Dom.Image._actualSize[ img.src ] = [ w, h ];
\r
79 remove && xnode.destroy();
\r
87 * URL: http://d.hatena.ne.jp/uupaa/20080413/1208067631
\r
88 * AUTHOR: uupaa.js@gmail.com
\r
91 Loader : X.EventDispatcher.inherits(
\r
93 X.Class.POOL_OBJECT,
\r
103 Constructor : function( abspath, delay, timeout ){
\r
106 this.abspath = abspath;
\r
107 this.delay = delay || 100;
\r
108 this.timeout = timeout || 10000;
\r
111 window[ 'Image' ] ?
\r
112 X.Dom.Node( img = new Image() ) :
\r
113 X.Dom.Node._systemNode.create( 'img', { src : abspath } )
\r
115 .listen( 'load', this )
\r
116 .listen( 'error', this )
\r
117 .listen( 'abort', this )
\r
118 .listen( X.Dom.Event.LOAD_ASSET_COMPLETE, this )
\r
119 .listen( X.Dom.Event.LOAD_ASSET_ERROR, this );
\r
120 img && ( img.src = abspath );
\r
123 handleEvent : function( e ){
\r
128 if( this.finish ) return;
\r
129 this.finish = true;
\r
130 this.timerID = this.asyncDispatch( 0, { type : X.Dom.Event.LOAD_ASSET_ERROR } );
\r
133 // if( finish === true ) return; // これがあると firefox3.6 で駄目、、、
\r
134 // if( timer ) return; // これがあると safari3.2 で駄目、、、
\r
135 this.finish = true;
\r
136 this.timerID && X.Timer.remove( this.timerID );
\r
137 if( window.opera && !this.xnode._rawNode.complete ){
\r
138 this.timerID = this.asyncDispatch( 0, { type : X.Dom.Event.LOAD_ASSET_ERROR } );
\r
141 size = X.Dom.Image.getActualDimension( X.UA.IE && X.UA.IE < 9 && window.Image ? this.abspath : this.xnode );
\r
142 this.timerID = this.asyncDispatch( 0, {
\r
143 type : X.Dom.Event.LOAD_ASSET_COMPLETE,
\r
144 src : this.abspath,
\r
149 case X.Dom.Event.LOAD_ASSET_COMPLETE :
\r
150 case X.Dom.Event.LOAD_ASSET_ERROR :
\r
151 delete this.timerID;
\r
152 X.Timer.once( 0, this, this.kill );
\r
156 _detect : function(){
\r
157 if( this.finish === true ) return;
\r
158 if( this.xnode._rawNode && this.xnode._rawNode.complete ){
\r
159 this.finish = true;
\r
160 if( this.xnode._rawNode.width ) return;
\r
161 this.timerID = this.asyncDispatch( 0, { type : X.Dom.Event.LOAD_ASSET_ERROR } );
\r
164 if( ( this.tick += this.delay ) > this.timeout ){
\r
165 this.finish = true;
\r
166 this.timerID = this.asyncDispatch( 0, { type : X.Dom.Event.LOAD_ASSET_ERROR, msg : 'timeout' } );
\r
169 this.timerID = X.Timer.once( this.delay, this, this._detect );
\r
172 // if( this.dispatch( { type : X.Dom.Event.LOAD_BEFORE_STOP } ) & X.Callback.CANCEL_NOW ) return;
\r
174 // this.dispacth( { type : X.Dom.Event.LOAD_ASSET_STOPED } );
\r
177 onKill : function(){
\r
178 this.timerID && X.Timer.remove( this.timerID );
\r
179 this.xnode.destroy();
\r