X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F04_net%2F00_XNet.js;h=88db71bf60447a72640367e373f1f468579f0a8b;hb=3525f9ca3b6a7e3e419fa1ea988925a6a9ff5ad5;hp=a60ee42045e0e6e1bd181f004c777ef32e62152e;hpb=05d60a7e55a635b3948204a577d9dcf2961e344b;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/04_net/00_XNet.js b/0.6.x/js/04_net/00_XNet.js index a60ee42..88db71b 100644 --- a/0.6.x/js/04_net/00_XNet.js +++ b/0.6.x/js/04_net/00_XNet.js @@ -1,30 +1,57 @@ // TODO onlineevent offlineevent, netspeed X.Net = { - get : function( url ){ - return new X_NET_Queue( X_NET_TYPE_XHR, { get : url } ); + xhrGet : function( url ){ + return new X_NET_Queue( X_NET_TYPE_XHR, { method : 'GET', url : url } ); }, - post : function( url ){ - return new X_NET_Queue( X_NET_TYPE_XHR, { post : url } ); + xhrPost : function( url, data ){ + return new X_NET_Queue( X_NET_TYPE_XHR, { method : 'POST', url : url, postbody : postbody } ); + }, + + formGet : function(){ + + }, + + formPost : function(){ + }, // TODO chashe - jsonp : function( url ){ + // TODO iframe useful or not. + // TODO file: では http: は使えない + jsonp : function( url, useIframe ){ return new X_NET_Queue( X_NET_TYPE_JSONP, url ); + }, + + image : function( url, useIframe ){ + return new X_NET_Queue( X_NET_TYPE_IMAGE, url ); + }, + + amountQueue : function(){ + return X_NET_QUEUE_LIST.length; } }; + +var X_NET_IWrapper = function(){}; + X_NET_IWrapper.prototype.load = function(){}; + X_NET_IWrapper.prototype.cancel = function(){}; + X_NET_IWrapper.prototype.reset = function(){}; + + var X_NET_TYPE_XHR = 1, X_NET_TYPE_JSONP = 2, X_NET_TYPE_FORM = 3, + X_NET_TYPE_IMAGE = 4, X_NET_QUEUE_LIST = [], X_NET_XHRWrapper, X_NET_JSONPWrapper, - X_NET_FORMWrapper, + X_NET_FormWrapper, + X_NET_ImageWrapper, X_NET_currentWrapper, X_NET_currentQueue, @@ -40,14 +67,21 @@ var X_NET_TYPE_XHR = 1, this.type = type; this.data = data; + this.listen( X.Event.COMPLETE, X_NET_proxyDispatch ); + X_NET_QUEUE_LIST[ X_NET_QUEUE_LIST.length ] = this; !X_NET_currentQueue && X_NET_shiftQueue(); }, + busy : function(){ + return this === X_NET_currentQueue && X_NET_currentWrapper._busy; + }, + cancel : function(){ var i = X_NET_QUEUE_LIST.indexOf( this ); if( i !== -1 ){ X_NET_QUEUE_LIST.splice( i, 1 ); + this.asyncDispatch( 0, { type : X.Event.CANCELED } ); } else if( this === X_NET_currentQueue ){ X_NET_currentWrapper.cancel(); @@ -58,14 +92,28 @@ var X_NET_TYPE_XHR = 1, function X_NET_proxyDispatch( e ){ switch( e.type ){ + case X.Event.BEFORE_KILL_INSTANCE : + break; + case X.Event.KILL_INSTANCE : + break; + case X.Event.KILL_INSTANCE_CANCELED : + break; + case X.Event.PROGRESS : + console.log( 'q: ' + e.type ); + this.dispatch( e ); + break; case X.Event.SUCCESS : case X.Event.ERROR : - this.asyncDispatch( 0, e ); - //this.kill(); - X_NET_shiftQueue(); + case X.Event.CANCELED : + console.log( 'q: ' + e.type ); + this.dispatch( e ); + this.asyncDispatch( 0, { type : X.Event.COMPLETE } ); break; - case X.Event.PROGRESS : - this.dispatch( 0, e ); + case X.Event.COMPLETE : + console.log( 'complete. then kill()' ); + this.kill(); + X_NET_shiftQueue(); + break; }; }; @@ -74,13 +122,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 ); - }; - - 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 ){ @@ -91,7 +140,10 @@ function X_NET_shiftQueue(){ X_NET_currentWrapper = X_NET_JSONPWrapper; break; case X_NET_TYPE_FORM : - X_NET_currentWrapper = X_NET_FORMWrapper; + X_NET_currentWrapper = X_NET_FormWrapper; + break; + case X_NET_TYPE_IMAGE : + X_NET_currentWrapper = X_NET_ImageWrapper; break; };