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 img = xnode._ie4getRawNode ? xnode._ie4getRawNode() : xnode._rawNode;
\r
28 if( XnodeOrImageElemOrSrc.constructor === X.Dom.Node ){
\r
29 xnode = XnodeOrImageElemOrSrc;
\r
30 img = xnode._ie4getRawNode ? xnode._ie4getRawNode() : xnode._rawNode;
\r
32 if( X.Type.isHTMLElement( XnodeOrImageElemOrSrc ) ){
\r
33 img = XnodeOrImageElemOrSrc;
\r
37 if( ret = X.Dom.Image._actualSize[ img.src ] ) return ret;
\r
40 // for Firefox, Safari, Google Chrome
\r
41 if( img.naturalWidth ) return [ img.naturalWidth, img.naturalHeight ];
\r
43 if( X.UA.IE && 5 <= X.UA.IE ){// for IE
\r
44 run = img.runtimeStyle;
\r
48 // keep runtimeStyle
\r
51 run.height = 'auto';
\r
57 } else {// for Opera and Other
\r
61 // keep current style
\r
62 img.removeAttribute( 'width' );
\r
63 img.removeAttribute( 'height' );
\r
71 ret = X.Dom.Image._actualSize[ img.src ] = [ w, h ];
\r
73 remove && xnode.destroy();
\r
81 * URL: http://d.hatena.ne.jp/uupaa/20080413/1208067631
\r
82 * AUTHOR: uupaa.js@gmail.com
\r
85 Loader : X.EventDispatcher.inherits(
\r
87 X.Class.POOL_OBJECT,
\r
97 Constructor : function( abspath, delay, timeout ){
\r
100 this.abspath = abspath;
\r
101 this.delay = delay;
\r
102 this.timeout = timeout;
\r
106 X.Dom.Node( img = new Image() ) :
\r
107 X.Dom.Node._systemNode.create( 'img', { src : abspath } )
\r
109 .listen( 'load', this )
\r
110 .listen( 'error', this )
\r
111 .listen( 'abort', this )
\r
112 .listen( X.Dom.Event.LOAD_ASSET_COMPLETE, this )
\r
113 .listen( X.Dom.Event.LOAD_ASSET_ERROR, this );
\r
115 img && ( img.src = abspath );
\r
119 handleEvent : function( e ){
\r
124 if( this.finish ) return;
\r
125 this.finish = true;
\r
126 this.timerID = this.asyncDispatch( 0, { type : X.Dom.Event.LOAD_ASSET_ERROR } );
\r
129 // if( finish === true ) return; // これがあると firefox3.6 で駄目、、、
\r
130 // if( timer ) return; // これがあると safari3.2 で駄目、、、
\r
131 this.finish = true;
\r
132 this.timerID && X.Timer.remove( this.timerID );
\r
133 if( window.opera && !this.xnode._rawNode.complete ){
\r
134 this.timerID = this.asyncDispatch( 0, { type : X.Dom.Event.LOAD_ASSET_ERROR } );
\r
137 size = X.Dom.Image.getActualDimension( X.UA.IE && X.UA.IE < 9 && window.Image ? this.abspath : this.xnode );
\r
138 this.timerID = this.asyncDispatch( 0, {
\r
139 type : X.Dom.Event.LOAD_ASSET_COMPLETE,
\r
140 src : this.abspath,
\r
145 case X.Dom.Event.LOAD_ASSET_COMPLETE :
\r
146 case X.Dom.Event.LOAD_ASSET_ERROR :
\r
147 delete this.timerID;
\r
148 X.Timer.once( 0, this, this.kill );
\r
152 _detect : function(){
\r
153 if( this.finish === true ) return;
\r
154 if( this.xnode._rawNode.complete ){
\r
155 this.finish = true;
\r
156 if( this.xnode._rawNode.width ) return;
\r
157 this.timerID = this.asyncDispatch( 0, { type : X.Dom.Event.LOAD_ASSET_ERROR } );
\r
160 if( ( this.tick += this.delay ) > this.timeout ){
\r
161 this.finish = true;
\r
162 this.timerID = this.asyncDispatch( 0, { type : X.Dom.Event.LOAD_ASSET_ERROR } );
\r
165 this.timerID = X.Timer.once( this.delay, this, this._detect );
\r
168 // if( this.dispatch( { type : X.Dom.Event.LOAD_BEFORE_STOP } ) & X.Callback.CANCEL_NOW ) return;
\r
170 // this.dispacth( { type : X.Dom.Event.LOAD_ASSET_STOPED } );
\r
173 onKill : function(){
\r
174 this.timerID && X.Timer.remove( this.timerID );
\r
175 this.xnode.destroy();
\r