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_URL_toAbsolutePath( XnodeOrImageElemOrSrc ) ] ) return ret;
\r
16 xnode = X.Dom.Node._systemNode.create(
\r
19 src : XnodeOrImageElemOrSrc
\r
22 position : 'absolute'
\r
25 Node._body._startUpdate();
\r
26 img = xnode._ie4getRawNode ? xnode._ie4getRawNode() : xnode._rawObject;
\r
29 if( XnodeOrImageElemOrSrc.constructor === X.Dom.Node ){
\r
30 xnode = XnodeOrImageElemOrSrc;
\r
31 img = xnode._ie4getRawNode ? xnode._ie4getRawNode() : xnode._rawObject;
\r
33 if( X.Type.isHTMLElement( XnodeOrImageElemOrSrc ) ){
\r
34 img = XnodeOrImageElemOrSrc;
\r
36 if( XnodeOrImageElemOrSrc.constructor === X.EventDispatcher && X.Type.isImage( XnodeOrImageElemOrSrc._rawObject ) ){
\r
37 xnode = XnodeOrImageElemOrSrc;
\r
38 img = xnode._rawObject;
\r
42 if( ret = X.Dom.Image._actualSize[ img.src ] ) return ret;
\r
45 // for Firefox, Safari, Google Chrome
\r
46 if( img.naturalWidth ) return [ img.naturalWidth, img.naturalHeight ];
\r
48 if( X.UA.IE && 5 <= X.UA.IE ){// for IE
\r
49 run = img.runtimeStyle;
\r
53 // keep runtimeStyle
\r
56 run.height = 'auto';
\r
62 } else {// for Opera and Other
\r
64 memW = w = img.width;
\r
65 memH = h = img.height;
\r
67 if( img.removeAttribute ){ // Safari1.3 の Image は removeAttribute がない
\r
68 // keep current style
\r
69 img.removeAttribute( 'width' );
\r
70 img.removeAttribute( 'height' );
\r
81 ret = X.Dom.Image._actualSize[ img.src ] = [ w, h ];
\r
83 remove && xnode.destroy();
\r
91 * URL: http://d.hatena.ne.jp/uupaa/20080413/1208067631
\r
92 * AUTHOR: uupaa.js@gmail.com
\r
95 Loader : X.EventDispatcher.inherits(
\r
97 X.Class.POOL_OBJECT,
\r
108 Constructor : function( abspath, delay, timeout ){
\r
111 this.abspath = abspath;
\r
112 this.delay = delay || 100;
\r
113 this.timeout = timeout || 10000;
\r
116 window[ 'Image' ] ?
\r
117 X.EventDispatcher( img = new Image() ) :
\r
118 X.Dom.Node._systemNode.create( 'img', { src : abspath } )
\r
120 .listen( [ 'load', 'error', 'abort', X.Event.SUCCESS, X.Event.ERROR, X.Event.KILL_INSTANCE ], this );
\r
121 img && ( img.src = abspath );
\r
124 handleEvent : function( e ){
\r
129 if( this.finish ) return;
\r
130 this.finish = true;
\r
131 this.timerID = this.asyncDispatch( { type : X.Event.ERROR } );
\r
134 // if( finish === true ) return; // これがあると firefox3.6 で駄目、、、
\r
135 // if( timer ) return; // これがあると safari3.2 で駄目、、、
\r
136 this.finish = true;
\r
137 this.timerID && X.Timer.remove( this.timerID );
\r
138 if( window.opera && !this.xnode._rawObject.complete ){
\r
139 this.timerID = this.asyncDispatch( { type : X.Event.ERROR } );
\r
142 size = X.Dom.Image.getActualDimension( X.UA.IE < 9 ? this.abspath : this.xnode );
\r
143 this.timerID = this.asyncDispatch( {
\r
144 type : X.Event.SUCCESS,
\r
145 src : this.abspath,
\r
150 case X.Event.SUCCESS :
\r
151 case X.Event.ERROR :
\r
152 delete this.timerID;
\r
153 X.Timer.once( 0, this, this.kill );
\r
155 case X.Event.KILL_INSTANCE :
\r
156 this.timerID && X.Timer.remove( this.timerID );
\r
157 this.xnode.destroy && this.xnode.destroy();
\r
162 _detect : function(){
\r
163 if( this.finish === true ) return;
\r
164 if( this.xnode._rawObject && this.xnode._rawObject.complete ){
\r
165 this.finish = true;
\r
166 if( this.xnode._rawObject.width ) return;
\r
167 this.timerID = this.asyncDispatch( { type : X.Event.ERROR } );
\r
170 if( ( this.tick += this.delay ) > this.timeout ){
\r
171 this.finish = true;
\r
172 this.timerID = this.asyncDispatch( { type : X.Event.ERROR, msg : 'timeout' } );
\r
175 this.timerID = X.Timer.once( this.delay, this, this._detect );
\r
178 // if( this.dispatch( { type : X.Event.BEFORE_CANCEL } ) & X.Callback.CANCEL_NOW ) return;
\r
180 // this.dispacth( { type : X.Event.CANCELED } );
\r