From 6181af63f34ee39cd4ff0eae2fe9b814c4229a02 Mon Sep 17 00:00:00 2001 From: itozyun Date: Tue, 16 Sep 2014 22:40:28 +0900 Subject: [PATCH] Version 0.6.80, bugfix for .instanceOf(). --- 0.6.x/js/00_core/02_XType.js | 17 ++++++++++++++++- 0.6.x/js/00_core/04_XClass.js | 14 +++++++++++--- 0.6.x/js/00_core/05_XTimer.js | 20 ++++++++++++++------ 0.6.x/js/01_dom/20_XDomImage.js | 4 ++++ 0.6.x/js/04_net/00_XNet.js | 29 ++++++++++++++-------------- 0.6.x/js/04_net/01_XNetXHR.js | 36 +++++++++++++---------------------- 0.6.x/js/04_net/02_XNetJSONP.js | 42 ++++++++++++++++++++++++----------------- 7 files changed, 97 insertions(+), 65 deletions(-) diff --git a/0.6.x/js/00_core/02_XType.js b/0.6.x/js/00_core/02_XType.js index 005ea3e..c97f5fc 100644 --- a/0.6.x/js/00_core/02_XType.js +++ b/0.6.x/js/00_core/02_XType.js @@ -49,13 +49,28 @@ X.Type = { isHTMLElement : new Function( 'v', ( X.UA.IE4 || X.UA.MacIE ) ? - 'return v&&v.tagName' : // ie4 or MacIE5.23, v.all <- error + 'return v&&v.tagName' : // ie4 or MacIE5.23, v.all <- error window[ 'HTMLElement' ] ? 'return v instanceof HTMLElement' : //window[ 'Element' ] ? // 'return v instanceof Element' : // error @ie8 'return v&&v.nodeType===1&&v.appendChild' ), + + /* + * new Image した場合に HTMLElement の img が作られるブラウザもある + */ + isImage : + function( v ){ + if( v && v.constructor === window.Image ) return true; + if( v && v.constructor === window.HTMLImageElement ) return true; + if( X.UA.WebKit < 525.13 ){ // Safari3- + if( v && v.src !== undefined && v.onload !== undefined && X.Type.isNumber( v.height ) && X.Type.isNumber( v.width ) && X.Type.isBoolean( v.complete ) ){ + return true; + }; + }; + return false; + }, /* isElementCollection : function(v) { return (Object.prototype.toString.call(v) === "[object HTMLCollection]"); diff --git a/0.6.x/js/00_core/04_XClass.js b/0.6.x/js/00_core/04_XClass.js index 76e0957..dfe3340 100644 --- a/0.6.x/js/00_core/04_XClass.js +++ b/0.6.x/js/00_core/04_XClass.js @@ -78,12 +78,15 @@ X.Class = ( function(){ klass = X.Class.create.apply( X.Class, params ); traits = null; + def = X.Class._getClassDef( klass ); // 継承用プロパティを控える if( opt_super === true ){ - def = X.Class._getClassDef( klass ); + def.superAccess = true; def.Super = Super; def.SuperProto = Super.prototype; def.SuperConstructor = superDef[ CONSTRUCTOR ] || superDef.SuperConstructor; + } else { + def.Super = Super; // instanceOf() で親クラスを調べる! }; return klass; @@ -107,7 +110,9 @@ X.Class = ( function(){ // onKill() === false の場合、kill のキャンセル // private は false での キャンセル は無視される + if( this.instanceOf( X.EventDispatcher ) ){ + console.log( 'this.instanceOf( X.EventDispatcher )! ' + this._dispatching ); if( !def.isPrivate ){ if( this._dispatching ){ this.dispatch( X.Event.BEFORE_KILL_INSTANCE ); @@ -119,8 +124,9 @@ X.Class = ( function(){ this.dispatch( X.Event.KILL_INSTANCE_CANCELED ); return; }; + } else { + this.dispatch( X.Event.BEFORE_KILL_INSTANCE ); }; - this.dispatch( X.Event.BEFORE_KILL_INSTANCE ); this.dispatch( X.Event.KILL_INSTANCE ); this._listeners && this.unlisten(); } else @@ -128,6 +134,8 @@ X.Class = ( function(){ return; }; + console.log('kill ' + this._dispatching); + for( p in instance ){ if( instance.hasOwnProperty && !instance.hasOwnProperty( p ) ) continue; delete instance[ p ]; @@ -200,7 +208,7 @@ X.Class = ( function(){ } else { def.live && def.live.push( instance ); }; - if( def.Super ){ + if( def.superAccess ){ // TODO klass.prototype に移動 instance.Super = def.SuperProto; instance.SuperConstructor = superConstructor; diff --git a/0.6.x/js/00_core/05_XTimer.js b/0.6.x/js/00_core/05_XTimer.js index 42b5157..a36d4b8 100644 --- a/0.6.x/js/00_core/05_XTimer.js +++ b/0.6.x/js/00_core/05_XTimer.js @@ -62,7 +62,8 @@ X.Timer = { list = X.Timer.TICKET_LIST, i = 0, l = list.length, - start = X.getTime(), + limit = X.getTime() + X.Timer.INTERVAL_TIME / 2, + heavy, q, f, c, r; if( X.Timer.busy ){ @@ -74,6 +75,10 @@ X.Timer = { for( ; i < l; ++i ){ q = list[ i ]; if( 0 < ( q.last -= next ) ) continue; + if( heavy ){ + if( q.last <= 0 ) q.last = 1; + continue; + }; c = q.count; if( q.k ){ @@ -83,6 +88,14 @@ X.Timer = { r = q.f(); }; + console.log( 'fire....' ); + + if( limit <= X.getTime() ){ + console.log( 'heavy' ); + // 関数の実行に時間が係る場合、次のタイミングに + heavy = true; + }; + if( r & X.Callback.UN_LISTEN || c === 1 ){ list.splice( i, 1 ); --i; @@ -91,11 +104,6 @@ X.Timer = { } else if( 1 < c ) --q.count; q.last = q.time; - - if( start < X.getTime() ){ - console.log( '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' ); - break; - }; }; X.Timer.timerId = 0; X.Timer.busy = false; diff --git a/0.6.x/js/01_dom/20_XDomImage.js b/0.6.x/js/01_dom/20_XDomImage.js index d1d417f..e5769b8 100644 --- a/0.6.x/js/01_dom/20_XDomImage.js +++ b/0.6.x/js/01_dom/20_XDomImage.js @@ -32,6 +32,10 @@ X.Dom.Image = { } else if( X.Type.isHTMLElement( XnodeOrImageElemOrSrc ) ){ img = XnodeOrImageElemOrSrc; + } else + if( XnodeOrImageElemOrSrc.constructor === X.EventDispatcher && X.Type.isImage( XnodeOrImageElemOrSrc._rawObject ) ){ + xnode = XnodeOrImageElemOrSrc; + img = xnode._rawObject; } else { return; }; diff --git a/0.6.x/js/04_net/00_XNet.js b/0.6.x/js/04_net/00_XNet.js index 3f6e492..d3604f4 100644 --- a/0.6.x/js/04_net/00_XNet.js +++ b/0.6.x/js/04_net/00_XNet.js @@ -2,11 +2,11 @@ X.Net = { xhrGet : function( url ){ - return new X_NET_Queue( X_NET_TYPE_XHR, { type : 'get', get : url } ); + return new X_NET_Queue( X_NET_TYPE_XHR, { method : 'GET', get : url } ); }, xhrPost : function( url ){ - return new X_NET_Queue( X_NET_TYPE_XHR, { type : 'post', post : url } ); + return new X_NET_Queue( X_NET_TYPE_XHR, { method : 'POST', post : url } ); }, formGet : function(){ @@ -59,7 +59,7 @@ var X_NET_TYPE_XHR = 1, this.type = type; this.data = data; - this.listen( X.Event.COMPLETE, this, X_NET_proxyDispatch ); + this.listen( X.Event.COMPLETE, X_NET_proxyDispatch ); X_NET_QUEUE_LIST[ X_NET_QUEUE_LIST.length ] = this; !X_NET_currentQueue && X_NET_shiftQueue(); @@ -73,7 +73,7 @@ var X_NET_TYPE_XHR = 1, var i = X_NET_QUEUE_LIST.indexOf( this ); if( i !== -1 ){ X_NET_QUEUE_LIST.splice( i, 1 ); - this.asyncDispatch( 0, { type : X.Event.COMPLETE } ); + this.asyncDispatch( 0, { type : X.Event.CANCELED } ); } else if( this === X_NET_currentQueue ){ X_NET_currentWrapper.cancel(); @@ -96,17 +96,16 @@ function X_NET_proxyDispatch( e ){ break; case X.Event.SUCCESS : case X.Event.ERROR : + case X.Event.CANCELED : console.log( 'q: ' + e.type ); this.dispatch( e ); this.asyncDispatch( 0, { type : X.Event.COMPLETE } ); break; - case X.Event.CANCELED : - - break; case X.Event.COMPLETE : + console.log( 'complete. then kill()' ); this.kill(); X_NET_shiftQueue(); - break; + break; }; }; @@ -115,14 +114,14 @@ function X_NET_shiftQueue(){ if( X_NET_currentQueue ){ if( X_NET_currentWrapper._busy ) return; - X_NET_currentWrapper.unlisten( [ X.Event.SUCCESS, X.Event.ERROR, X.Event.PROGRESS ], X_NET_currentQueue, X_NET_proxyDispatch ); - X_NET_currentQueue.reset(); - }; - - if( !X_NET_QUEUE_LIST.length ){ + X_NET_currentWrapper + .unlisten( [ X.Event.SUCCESS, X.Event.ERROR, X.Event.PROGRESS ], X_NET_currentQueue, X_NET_proxyDispatch ) + .reset(); X_NET_currentQueue = X_NET_currentWrapper = null; - return; }; + + if( !X_NET_QUEUE_LIST.length ) return; + queue = X_NET_QUEUE_LIST.shift(); switch( queue.type ){ @@ -137,7 +136,7 @@ function X_NET_shiftQueue(){ break; }; - X_NET_currentWrapper.listen( [ X.Event.SUCCESS, X.Event.ERROR, X.Event.PROGRESS, X.Event.COMPLETE ], X_NET_currentQueue = queue, X_NET_proxyDispatch ); + X_NET_currentWrapper.listen( [ X.Event.SUCCESS, X.Event.ERROR, X.Event.PROGRESS ], X_NET_currentQueue = queue, X_NET_proxyDispatch ); X_NET_currentWrapper.load( queue.data ); }; diff --git a/0.6.x/js/04_net/01_XNetXHR.js b/0.6.x/js/04_net/01_XNetXHR.js index a7732f3..91330ef 100644 --- a/0.6.x/js/04_net/01_XNetXHR.js +++ b/0.6.x/js/04_net/01_XNetXHR.js @@ -57,6 +57,7 @@ if( X.Net.XHR.W3C || X_Net_XHR_ACTIVE_X ){ _rawObject : X_Net_XHR_W3C || X_Net_XHR_ACTIVE_X, _isXHR : true, + _isXDR : false, // for ie8 _method : null, _type : null, @@ -101,12 +102,13 @@ if( X.Net.XHR.W3C || X_Net_XHR_ACTIVE_X ){ }; }; + // send 前にフラグを立てる,回線が早いと raw.send() 内で onload -> _busy = false ののち、 _busy = true するケースがあるため。 + this._busy = true; + // http://allabout.co.jp/gm/gc/24097/#1 // sendをonreadystatechangeの前に記述すると、ieでは動作しなくなります、、、。 // konquerorでエラーが発生するのでここでは、とりあえず、send('') としました。 raw.send( postbody || '' ); - - this._busy = true; }, cancel : X.Net.XHR.CANCELABLE ? @@ -119,8 +121,7 @@ if( X.Net.XHR.W3C || X_Net_XHR_ACTIVE_X ){ reset : function(){ this._method = this._type = null; - this._canceled = false; - this._busy = false; + this._canceled = this._busy = false; this._lastProgress = 0; }, @@ -207,12 +208,14 @@ if( X.Net.XHR.W3C || X_Net_XHR_ACTIVE_X ){ case 'arraybuffer' : }; - console.log( 'status ' + status ); - //console.dir( raw ); + //console.log( 'status ' + status ); + //console.dir( raw ); + this._busy = false; this.asyncDispatch( 0, { type : X.Event.SUCCESS, status : status || 200, data : data } ); } else { console.log( 'status ' + status ); + this._busy = false; //console.dir( raw ); live && this.asyncDispatch( 0, { type : X.Event.ERROR, status : raw.status || 0, percent : 100 } ); }; @@ -227,18 +230,18 @@ if( X.Net.XHR.W3C || X_Net_XHR_ACTIVE_X ){ case 'error' : //console.dir( e ); + this._busy = false; live && this.asyncDispatch( 0, { type : X.Event.ERROR, status : raw.status } ); break; //case 'abort' : + // this._busy = false; // this.asyncDispatch( 0, { type : X.Event.ERROR, status : raw.status } ); // break; case 'timeout' : // Gecko 12.0 https://developer.mozilla.org/ja/docs/XMLHttpRequest/Synchronous_and_Asynchronous_Requests + this._busy = false; live && this.asyncDispatch( 0, { type : X.Event.ERROR, status : raw.status } ); break; - - case 'loadend' : - break; }; }, @@ -253,7 +256,7 @@ if( X.Net.XHR.W3C || X_Net_XHR_ACTIVE_X ){ // 同期リクエストでなければならない場合, unload, beforeunload時 - // ie8 では timeout が有効 + // ie8 では timeout が有効, MSXML のバージョンで決定すべき? if( X.UA.IE8 ){ X_NET_XHRWrapper.listen( [ 'readystatechange', 'error', 'abort', 'timeout' ] ); } else @@ -272,18 +275,5 @@ if( X.Net.XHR.W3C || X_Net_XHR_ACTIVE_X ){ if( X.Net.XHR.UL_PROGRESS ){ X_NET_XHRWrapper._rawObject.upload.addEventListener( 'progress', X.Net.XHR.xhr.onUploadProgress ); }; - - - var X_NET_XHR_lastReadyState = 0; - - function X_NET_XHR_checkReadyStateTimer(){ - //console.log( '-' ); - if( X_NET_XHR_lastReadyState < X_NET_XHRWrapper._rawObject.readyState ){ - X_NET_XHR_lastReadyState = X_NET_XHRWrapper._rawObject.readyState; - X_NET_XHRWrapper.dispatch( { type : 'readystatechange' } ); - console.log( '- ' + X_NET_XHR_lastReadyState ); - if( 4 <= X_NET_XHR_lastReadyState ) return X.Callback.UN_LISTEN; - }; - }; }; diff --git a/0.6.x/js/04_net/02_XNetJSONP.js b/0.6.x/js/04_net/02_XNetJSONP.js index a9b2458..48d4371 100644 --- a/0.6.x/js/04_net/02_XNetJSONP.js +++ b/0.6.x/js/04_net/02_XNetJSONP.js @@ -10,6 +10,8 @@ X.Net.JSONP = { cb : function( accessKey, jsonString, time, opt_json2FileSize ){ if( accessKey !== X_NET_JSONP_ACCESS_KEY ) return; + X_NET_JSONPWrapper._busy = false; + X_NET_JSONPWrapper .asyncDispatch( 0, { type : jsonString ? X.Event.SUCCESS : X.Event.ERROR, @@ -22,25 +24,32 @@ X.Net.JSONP = { var X_NET_JSONP_ACCESS_KEY = Math.random(), - X_NET_JSONP_NinjaIframe, - - X_NET_JSONP_imageFixListener = X.UA.Opera && function( e ){ - switch( e.type ){ - case X.Event.SUCCESS : - case X.Event.ERROR : - X_NET_JSONP_loadScriptInNinjaIframe( e.src ); - case X.Event.TIMEOUT : - case X.Event.CANCELED : - }; + X_NET_JSONP_NinjaIframe; + + +function X_NET_JSONP_operaImageHandleEvent( e ){ + switch( e.type ){ + case X.Event.SUCCESS : + case X.Event.ERROR : + X_NET_JSONP_loadScriptInNinjaIframe( e.src ); + break; + case X.Event.TIMEOUT : + case X.Event.CANCELED : + X_NET_JSONPWrapper._operaImage.unlisten().reset(); + X_NET_JSONPWrapper.asyncDispatch( 0, X.Event.ERROR ); + break; }; +}; +if( !X.UA.Opera ) X_NET_JSONP_operaImageHandleEvent = null; + function X_NET_JSONP_loadScriptInNinjaIframe( url ){ - X_NET_JSONP_NinjaIframe || ( X_NET_JSONP_NinjaIframe = new X.Util.NinjaIframe() ); - var json2Path = 'js/libs/json2.js', json2FileSize = 18103, html; + X_NET_JSONP_NinjaIframe || ( X_NET_JSONP_NinjaIframe = new X.Util.NinjaIframe() ); + if( X.UA.IE8 ){ html = [ // http://blog.livedoor.jp/dankogai/archives/51503830.html @@ -136,16 +145,15 @@ X_NET_JSONPWrapper = X.Class._override( new X.EventDispatcher(), { - _operaImage : null, // X.Dom.Image.Loader(); + _operaImage : null, // X.Net.Image(); _busy : false, _canceled : false, load : function( url, data, timeout ){ - //createURL - if( X_NET_JSONP_imageFixListener ){ - this._operaImage = X.Dom.Image.Loader( url ) - .listenOnce( [ X.Event.SUCCESS, X.Event.ERROR ], X_NET_JSONP_imageFixListener ); + if( X_NET_JSONP_operaImageHandleEvent ){ + this._operaImage = X.Net.Image( url ) + .listenOnce( [ X.Event.SUCCESS, X.Event.ERROR ], X_NET_JSONP_operaImageHandleEvent ); } else { X_NET_JSONP_loadScriptInNinjaIframe( url ); }; -- 2.11.0