1 // TODO onlineevent offlineevent, netspeed
\r
4 xhrGet : function( url ){
\r
5 return new X_NET_Queue( X_NET_TYPE_XHR, { type : 'get', get : url } );
\r
8 xhrPost : function( url ){
\r
9 return new X_NET_Queue( X_NET_TYPE_XHR, { type : 'post', post : url } );
\r
12 formGet : function(){
\r
16 formPost : function(){
\r
21 jsonp : function( url ){
\r
22 return new X_NET_Queue( X_NET_TYPE_JSONP, url );
\r
32 var X_NET_IWrapper = function(){};
\r
33 X_NET_IWrapper.prototype.load = function(){};
\r
34 X_NET_IWrapper.prototype.cancel = function(){};
\r
35 X_NET_IWrapper.prototype.reset = function(){};
\r
38 var X_NET_TYPE_XHR = 1,
\r
39 X_NET_TYPE_JSONP = 2,
\r
40 X_NET_TYPE_FORM = 3,
\r
42 X_NET_QUEUE_LIST = [],
\r
48 X_NET_currentWrapper,
\r
51 X_NET_Queue = X.EventDispatcher.inherits(
\r
53 X.Class.POOL_OBJECT,
\r
58 Constructor : function( type, data ){
\r
62 this.listen( X.Event.COMPLETE, this, X_NET_proxyDispatch );
\r
64 X_NET_QUEUE_LIST[ X_NET_QUEUE_LIST.length ] = this;
\r
65 !X_NET_currentQueue && X_NET_shiftQueue();
\r
69 return this === X_NET_currentQueue && X_NET_currentWrapper._busy;
\r
72 cancel : function(){
\r
73 var i = X_NET_QUEUE_LIST.indexOf( this );
\r
75 X_NET_QUEUE_LIST.splice( i, 1 );
\r
76 this.asyncDispatch( 0, { type : X.Event.COMPLETE } );
\r
78 if( this === X_NET_currentQueue ){
\r
79 X_NET_currentWrapper.cancel();
\r
85 function X_NET_proxyDispatch( e ){
\r
87 case X.Event.BEFORE_KILL_INSTANCE :
\r
89 case X.Event.KILL_INSTANCE :
\r
91 case X.Event.KILL_INSTANCE_CANCELED :
\r
93 case X.Event.PROGRESS :
\r
94 console.log( 'q: ' + e.type );
\r
97 case X.Event.SUCCESS :
\r
98 case X.Event.ERROR :
\r
99 console.log( 'q: ' + e.type );
\r
100 this.dispatch( e );
\r
101 this.asyncDispatch( 0, { type : X.Event.COMPLETE } );
\r
103 case X.Event.CANCELED :
\r
106 case X.Event.COMPLETE :
\r
108 X_NET_shiftQueue();
\r
113 function X_NET_shiftQueue(){
\r
116 if( X_NET_currentQueue ){
\r
117 if( X_NET_currentWrapper._busy ) return;
\r
118 X_NET_currentWrapper.unlisten( [ X.Event.SUCCESS, X.Event.ERROR, X.Event.PROGRESS ], X_NET_currentQueue, X_NET_proxyDispatch );
\r
119 X_NET_currentQueue.reset();
\r
122 if( !X_NET_QUEUE_LIST.length ){
\r
123 X_NET_currentQueue = X_NET_currentWrapper = null;
\r
126 queue = X_NET_QUEUE_LIST.shift();
\r
128 switch( queue.type ){
\r
129 case X_NET_TYPE_XHR :
\r
130 X_NET_currentWrapper = X_NET_XHRWrapper;
\r
132 case X_NET_TYPE_JSONP :
\r
133 X_NET_currentWrapper = X_NET_JSONPWrapper;
\r
135 case X_NET_TYPE_FORM :
\r
136 X_NET_currentWrapper = X_NET_FORMWrapper;
\r
140 X_NET_currentWrapper.listen( [ X.Event.SUCCESS, X.Event.ERROR, X.Event.PROGRESS, X.Event.COMPLETE ], X_NET_currentQueue = queue, X_NET_proxyDispatch );
\r
142 X_NET_currentWrapper.load( queue.data );
\r