X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;ds=sidebyside;f=0.6.x%2Fjs%2F01_core%2F13_XEventDispatcher.js;h=25c2d11477034a160a6fcb231065e418636740b8;hb=7d3b5c3962eea3585a009bfc290a71560b2e83b3;hp=426a05dd762ab1ab8e368357f6e2dc8d1309aab7;hpb=541618cd9485cb041f46177d6869cc6d618ed1da;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/01_core/13_XEventDispatcher.js b/0.6.x/js/01_core/13_XEventDispatcher.js index 426a05d..25c2d11 100644 --- a/0.6.x/js/01_core/13_XEventDispatcher.js +++ b/0.6.x/js/01_core/13_XEventDispatcher.js @@ -1,4 +1,8 @@ /** + * + */ + +/** * X.EventDispatcher * * 1. as3 ã® EventDispatcher ã©ã¤ã¯ãªã¯ã©ã¹ããã®ã¾ã¾ä½¿ã£ãããç¶æ¿ããããã³ã¼ã«ããã¯ä¸ã«ã¤ãã³ãã追å ãããï¼åé¤ãããï¼ã«ã対å¦ãã¦ããã @@ -21,68 +25,45 @@ // ------------ local variables -------------------------------------------- // // ------------------------------------------------------------------------- // var X_EventDispatcher_once = false, + X_EventDispatcher_lock = false, + X_EventDispatcher_unlock = false, X_EventDispatcher_needsIndex = false, - X_EventDispatcher_temp = {}, - - X_EventDispatcher_safariPreventDefault = false; // // Safari3- - -if( X.UA.MacIE ){ - X_EventDispatcher_temp.DOM_W3C = true; - X_EventDispatcher_temp.EVENT_DOM0 = true; -} else -if( X.UA.IE4 ){ // ie4 & iemobi4 - X_EventDispatcher_temp.DOM_IE4 = true; - X_EventDispatcher_temp.EVENT_DOM0 = true; -} else -if( document.getElementById ){ - X_EventDispatcher_temp.DOM_W3C = true; - if( document.addEventListener ){ - X_EventDispatcher_temp.EVENT_W3C = true; - } else - if( document.attachEvent ){ - X_EventDispatcher_temp.EVENT_IE = true; - } else { - X_EventDispatcher_temp.EVENT_DOM0 = true; - }; -} else -if( document.all ){ - X_EventDispatcher_temp.DOM_IE4 = true; - X_EventDispatcher_temp.EVENT_DOM0 = true; -} else -if( document.layers ){ -} else { - -}; + X_EventDispatcher_safariPreventDefault = false; // Safari3- // ------------------------------------------------------------------------- // // --- interface ----------------------------------------------------------- // // ------------------------------------------------------------------------- // /** - * ã¤ãã³ãã¿ã¼ã²ãã(widnow, document, Image, XHR ç)ãã©ããããå ´åãé常ã¯ãnew æã«æ¸¡ãã¾ããåç §:ã³ã³ã¹ãã©ã¯ã¿å®ä½ {@link X.EventDispatcher.Constructor} - * ã¢ããªã±ã¼ã·ã§ã³ç¬èªã®ã¤ãã³ããããåããããã ããã¨ããå ´åãã¤ãã³ãã¿ã¼ã²ããã¯ä¸è¦ã§ãã + *
ã¤ãã³ãã¿ã¼ã²ãã(widnow, document, Image, XHR, Silverlight ç)ãã©ããããå ´åãé常㯠new æã«æ¸¡ãã¾ãã + *
åç §:ã³ã³ã¹ãã©ã¯ã¿å®ä½ {@link X.EventDispatcher.Constructor} + *
ã¢ããªã±ã¼ã·ã§ã³ç¬èªã®ã¤ãã³ããããåãããããã¨ããå ´åãã¤ãã³ãã¿ã¼ã²ããã¯ä¸è¦ã§ãã + * * @class * @classdesc EventTarget ãªãã¸ã§ã¯ããã©ããããããã¢ããªã±ã¼ã·ã§ã³ã§ç¬èªã«å®ç¾©ããã¤ãã³ããçºä¿¡ããããã®ã¯ã©ã¹ã§ãã - * listen, unlisten, dispatch ã¨ãã addEventListener, removeEventListener, dispatchEvent ã«å¯¾å¿ããé¢æ°ãæã¡ã¾ãã - * ããã« listening ã¨ãããas3 ã® hasEventListener ã«ç¸å½ããé¢æ°ãæã¡ã¾ãã - * ã¤ãã³ãã¿ã¼ã²ãããªãã¸ã§ã¯ã(widnow, document, HTMLElement, XHR ç)ã _rawObject ã«è¨å®ããã¦ããå ´åã«ããããã¸å®éã®ã¤ãã³ãç»é²ã»è§£é¤ãè¡ãã¾ãã - * ãã®ã¤ãã³ãã®ç»é²ã»è§£é¤ã¯ã¯ãã¹ãã©ã¦ã¶ã§ãIE5ï½8 ã®ç¬èªã¤ãã³ãã®å·®ç°ãå¸åããDOM0 ã«å¯¾ãã¦ãè¤æ°ã®ã³ã¼ã«ããã¯ãç»é²ãããã¨ãã§ãã¾ãã - * ã¾ãã³ã¼ã«ããã¯ã«å¯¾ãã¦ãthis ã³ã³ããã¹ããã追å ã®å¼æ°ãæå®ãã§ãã¾ãã this ã³ã³ããã¹ããæå®ããªãã£ãå ´åãEventDispatcher ã¤ã³ã¹ã¿ã³ã¹ãã³ã¼ã«ããã¯ã® this ã«ãªãã¾ãã - * @param {object=} opt_rawObject + *
listen, unlisten, dispatch ã¨ãã addEventListener, removeEventListener, dispatchEvent ã«å¯¾å¿ããé¢æ°ãæã¡ã¾ãã + *
ã¾ã listening ã¨ãã ActionScript3 ã® hasEventListener ã«ç¸å½ããé¢æ°ãæã¡ã¾ãã + *
ã¤ãã³ãã¿ã¼ã²ãããªãã¸ã§ã¯ã(widnow, document, HTMLElement, XHR ç)ã this._rawObject ã«è¨å®ããã¦ããå ´åã«ããããã¸å®éã®ã¤ãã³ãç»é²ã»è§£é¤ãè¡ãã¾ãã + *
ãã®ã¤ãã³ãã®ç»é²ã»è§£é¤ã¯ã¯ãã¹ãã©ã¦ã¶ã§ãIE5ï½8 ã®ç¬èªã¤ãã³ãã®å·®ç°ãå¸åããDOM0 ã«å¯¾ãã¦ãè¤æ°ã®ã³ã¼ã«ããã¯ãç»é²ãããã¨ãã§ãã¾ãã + *
ã¾ãã³ã¼ã«ããã¯ã«å¯¾ãã¦ãthis ã³ã³ããã¹ããã追å ã®å¼æ°ãæå®ãã§ãã¾ãã this ã³ã³ããã¹ããæå®ããªãã£ãå ´åãEventDispatcher ã¤ã³ã¹ã¿ã³ã¹ãã³ã¼ã«ããã¯ã® this ã«ãªãã¾ãã + *
unlisten() ã¯ãå¼æ°ãæå®ããªãã£ãå ´åãå ¨ã¦ã®ã¤ãã³ãã解é¤ãã¾ãããã ããsystemListen çµç±ã§ç»é²ããããã³ãã©ã¯è§£é¤ããã¾ããã + * systemListen, systemUnlisten ã¯ãã©ã¤ãã©ãªå ã®ã³ã¼ãããããã¢ã¯ã»ã¹ã§ãã¾ããã + * + * @augments X_Class_CommonProps + * + * @param {object=} opt_rawObject ã¤ãã³ãã¿ã¼ã²ãã(EventTarget) */ X.EventDispatcher = X.Class.create( 'EventDispatcher', - /** @lends {X.EventDispatcher.prototype} */ + /** @lends X.EventDispatcher.prototype */ { - /** - * @namespace - * @memberof X.EventDispatcher - */ + + // TODO _rawObjectType EventTarget, XHR, Silverlight, ... /** * ã¤ãã³ããªã¹ããã¤ãã³ãå(string)ãæ°å¤(1~,ãã¬ã¼ã ã¯ã¼ã¯å ã§å®ç¾©)ããã¼ã¨ããArrayã§è¨æ¶ãã¾ãã * Arrayã«ã¯ã{k:種é¡,x:ã³ã³ããã¹ã(thisObject),f:é¢æ°,s:ãµããªã¡ã³ãããå¼æ°ã®é å} ã¨ããããã·ã¥ãã¾ãã¯é¢æ°ãèãããã¦ãã¾ãã @@ -93,9 +74,9 @@ X.EventDispatcher = /** * _rawObject ã«ã¯ HTMLElement, window, document, XHR ã¨ãã£ãã¤ãã³ãã¿ã¼ã²ãããªãã¸ã§ã¯ããè¨å®ãã¾ãã - * _rawObject ãè¨å®ããã¦ãã㨠on(), off() æã« addEventListener(DOM Level2) ã detachEvent(ie5ï½8), onï½(DOM0) çãæä½ãã¾ãã - * _rawObject ã¯æåã® on() åã«è¨å®ãã¦ãããªã㨠addEventListener çãæå³ããããã«è¡ããã¾ããã - * X.Dom.Node ã§ã¯éåæã« HTMLElement ãçæãã¦ãã¦ãè¦ç´ çæ以åã« on, off ãå¼ã³åºããã¨ãã§ãã¾ããããã¯é©å®ã« migrateEvent, restoreEvent ãå¼ãã§è§£æ±ºãã¦ããããã§ãã + * _rawObject ãè¨å®ããã¦ãã㨠listen(), unlisten() æã« addEventListener(DOM Level2) ã detachEvent(ie5ï½8), onï½(DOM0) çãæä½ãã¾ãã + * _rawObject ã¯æåã® listen() åã«è¨å®ãã¦ãããªã㨠addEventListener çãæå³ããããã«è¡ããã¾ããã + * X.Node ã§ã¯éåæã« HTMLElement ãçæãã¦ãã¦ãè¦ç´ çæ以åã« listen, unlisten ãå¼ã³åºããã¨ãã§ãã¾ããããã¯é©å®ã« X_EventDispatcher_toggleAllEvents ãå¼ãã§è§£æ±ºãã¦ããããã§ãã * @private * @type {Object} */ @@ -109,7 +90,7 @@ X.EventDispatcher = */ '_handleEvent' : null, - /* + /** * dispatch ä¸ã« dispatch ãå¼ã°ããéã«ããã®ãã¹ãã®æ·±ããä¿åããã * dispatch() çµäºæã« _dispatching ã 0 ã®å ´åã«ãç¾å¨ã®ã¤ã³ã¹ã¿ã³ã¹ã® dispatch ããã¹ã¦çµãã£ããã¨ã«ãªãã * @private @@ -117,7 +98,7 @@ X.EventDispatcher = */ '_dispatching' : 0, // dispatch ä¸ã® unlisten ã§ä½¿ç¨ - /* + /** * dispatch ä¸ã« listen ãå¼ã°ããå ´åã«ãé åã®indexãããããã¨ãé¿ãããããä¸æ¦ä¿æããã * _dispatching ã 0 ã®ã¨ãã« _reserves ã使ã£ã¦ listen() ãå¼ã³åºãã * @private @@ -125,7 +106,7 @@ X.EventDispatcher = */ '_reserves' : null, - /* + /** * dispatch ä¸ã« unlisten ãå¼ã°ããå ´åã«ãé åã®indexãããããã¨ãé¿ãããããä¸æ¦ä¿æããã * _dispatching ã 0 ã®ã¨ãã« _unlistens ã使ã£ã¦ unlisten() ãå¼ã³åºãã * @private @@ -133,18 +114,26 @@ X.EventDispatcher = */ '_unlistens' : null, - /* + /** * dispatch ä¸ã« kill ãå¼ã°ããå ´åã«ãX.EventDispatcher ã¤ã³ã¹ã¿ã³ã¹ã®åé¤ã dispatch å¾ã«ãããããã«ç«ã¦ããã©ã°ã * @private * @type {boolean} */ '_killReserved' : false, + + /** + * asyncDispatch ä¸ã« kill ãå¼ã°ããå ´åã«ãX.EventDispatcher ã¤ã³ã¹ã¿ã³ã¹ã®åé¤ãæå¾ã®ã¿ã¤ãã¼ã®çºç«å¾ã«ãããããã«ç«ã¦ããã©ã°ã + * TODO asyncDispatch ã®è§£é¤ã¯ã©ããã? + * @private + * @type {boolean} + */ + '_lastLazyID' : false, /** * X.EventDispatcher ã®ã³ã³ã¹ãã©ã¯ã¿ã®å®ä½ã - *ã@constructs + * @@@constructs * @this {X.EventDispatcher} - * @params {object=} opt_rawObject + * @param {object=} opt_rawObject */ Constructor : function( opt_rawObject ){ if( opt_rawObject ){ @@ -159,12 +148,16 @@ X.EventDispatcher = * @param {(eventHash|string|number)} e */ dispatch : X_EventDispatcher_dispatch, - - /** - * - * @this {X.EventDispatcher} - */ - on : X_EventDispatcher_listen, + + /** + * + * @this {X.EventDispatcher} + * @param {(string|number|Array.<(string,number)>)} type + * @param {(listener|function|Array)=} opt_arg1 + * @param {(function|Array=} opt_arg2 + * @param {Array=} opt_arg3 + * @return {X.EventDispatcher} + */ listen : X_EventDispatcher_listen, /** @@ -182,21 +175,23 @@ X.EventDispatcher = X_EventDispatcher_once = false; return this; }, - - off : X_EventDispatcher_unlisten, + unlisten : X_EventDispatcher_unlisten, /** - * ã¤ãã³ããªã¹ãã®ç»é²ç¶æ³ãçå½å¤ã§è¿ããæ»ãå¤ãæ°å¤(index)ã®å ´åãããããããã¯å é¨ã®ã¿ã§ä½¿ç¨ã - * listening() 㨠type ãçç¥ããå ´åãä¸ã¤ã§ãç»é²ãããã° true ãè¿ãã - * listening( type ) 㨠type ã ããä¸ããå ´åããã® type ã«ç»é²ãããã° true ãè¿ãã - * type 㨠ã¤ãã³ããªã¹ãã®çµã¿åãããç»é²ããã¦ãããã調ã¹ãå ´åã¯ãlisten æã® thisObject ã args(Array) ãä¸è´ããã¦æ¸¡ãå¿ è¦ãããã + *
ã¤ãã³ããªã¹ãã®ç»é²ç¶æ³ãçå½å¤ã§è¿ããæ»ãå¤ãæ°å¤(index)ã®å ´åãããããããã¯å é¨ã®ã¿ã§ä½¿ç¨ã + *
this.listening(); ã®ããã« type ãçç¥ããå ´åãä¸ã¤ã§ãç»é²ãããã° true ãè¿ãã + *
this.listening( 'myevent' ); 㨠type ã ããä¸ããå ´åããã® type ã«ç»é²ãããã° true ãè¿ãã + *
type 㨠ã¤ãã³ããªã¹ãã®çµã¿åãããç»é²ããã¦ãããã調ã¹ãå ´åã¯ãlisten æã® thisObject ã args(Array) ãä¸è´ããã¦æ¸¡ãå¿ è¦ãããã + * + * @example * this.listen( [ 'myevent', 'yourevent' ], this, onMyEvent, args = [ 1, 'a' ] ); * this.listening( 'myevent', this, onMyEvent, args ) === true; + * * @this {X.EventDispatcher} * @return {(number|boolean)} * @param {(string|number)=} opt_type - * @param {(listener|function|Array)=} opt_arg1 + * @param {(listener|function|Array|callbackHash)=} opt_arg1 * @param {(function|Array=} opt_arg2 * @param {Array=} opt_arg3 */ @@ -211,7 +206,7 @@ X.EventDispatcher = if( opt_arg1.k ){ hash = opt_arg1; } else { - hash = X.Callback._classifyCallbackArgs( opt_arg1, opt_arg2, opt_arg3, this ); + hash = X_Callback_classifyCallbackArgs( opt_arg1, opt_arg2, opt_arg3, this ); }; if( ( unlistens = this._unlistens ) && ( unlistens = unlistens[ opt_type ] ) ){ @@ -222,7 +217,10 @@ X.EventDispatcher = }; for( i = list.length; i; ){ f = list[ --i ]; - if( f === hash || ( f.x === hash.x && f.f === hash.f && f.s === hash.s ) ) return X_EventDispatcher_needsIndex ? i : true; + if( f === hash || ( f.x === hash.x && f.f === hash.f && f.s === hash.s ) ){ + // index ãè¦æ±ãããå ´åãlock ããã¦ããªããã¾ã㯠unlock ãªã index ãè¿ã + return X_EventDispatcher_needsIndex ? ( X_EventDispatcher_unlock || !f.lock ? i : false ) : true; + }; }; return false; }, @@ -230,12 +228,16 @@ X.EventDispatcher = /** * delay(ããªç§)å¾ã«ã¤ãã³ãã dispatch ãããæ»ãå¤ã¯ uid = X.Timer.add() ã®ã¿ã¤ãã¼ID(æ°å¤)ãX.Timer.remove(uid) ã§ã¿ã¤ãã¼ã解é¤ã㦠dispatch ãä¸æ¢ã§ããã * @this {X.EventDispatcher} - * @return {number} - * @param {number=} delay - * @param {(eventHash|string|number)=} e + * @param {(number|eventHash|string)=} delay ms çç¥ããå ´å㯠0 ã¨ãã¦æ±ã asyncDispatch( 'myevent' ) -> asyncDispatch( 0, 'myevent' ) + * @param {(eventHash|string|number)=} e ã¤ãã³ãã表ãæ°å¤ãæååã{ type : XXX, ... } ãªãªãã¸ã§ã¯ã + * @return {number} X.Timer.add() ã®æ»ãå¤ */ asyncDispatch : function( delay, e ){ - return X.Timer.add( delay, 1, this, this.dispatch, [ e ] ); + if( delay && e === undefined ){ + e = delay; + delay = 0; + }; + return this[ '_lastLazyID' ] = X.Timer.add( delay, 1, this, X_EventDispatcher_dispatch, [ e ] ); } } ); @@ -252,9 +254,9 @@ X.EventDispatcher = */ function X_EventDispatcher_dispatch( e ){ var list = this[ '_listeners' ], - ret = X.Callback.NONE, + ret = X_Callback_NONE, type = e[ 'type' ], - unlistens, i, l, f, r, sysOnly; + unlistens, i, l, args, f, r, sysOnly; if( !list || !( list = list[ type || e ] ) ) return ret; @@ -279,15 +281,15 @@ function X_EventDispatcher_dispatch( e ){ }; if( unlistens && unlistens.indexOf( f ) !== -1 ) continue; - r = X.Callback.NONE; - if( f.k ){ - f.a = [ e ]; - r = X.Callback._proxyCallback( f ); - } else { - r = f.call( this, e ); - }; + //if( f !== X.emptyFunction ){ + // if( f.k ){ + r = X_Callback_proxyCallback( f, args || ( args = [ e ] ) ); + // } else { + // r = f.call( this, e ); + // }; + //}; - if( f.once || r & X.Callback.UN_LISTEN ){ + if( f.once || r & X_Callback_UN_LISTEN ){ // dispatch ä¸ã« unlisten ãä½ããããã¨ããã if( !unlistens ){ unlistens = this._unlistens || ( this._unlistens = {} ); @@ -303,12 +305,19 @@ function X_EventDispatcher_dispatch( e ){ }; if( ( --this._dispatching ) === 0 ){ + + if( this[ '_lastLazyID' ] && X_Timer_currentUID === this[ '_lastLazyID' ] ){ + delete this[ '_lastLazyID' ]; + }; + // dispatch ä¸ã« unlisten ãããè¦ç´ ã®åé¤ unlistens = this._unlistens; delete this._dispatching; delete this._unlistens; - + // _unlistens ã«å ¥ã£ã¦ãã callbackHash ã¯ãlock ãã¯ãªã¢ãã¦ãã + X_EventDispatcher_unlock = true; for( type in unlistens ){ + //if( X_EMPTY_OBJECT[ type ] ) continue; list = unlistens[ type ]; for( i = list.length; i; ){ this.unlisten( type, list[ --i ] ); @@ -316,6 +325,7 @@ function X_EventDispatcher_dispatch( e ){ list.length = 0; delete unlistens[ type ]; }; + X_EventDispatcher_unlock = false; if( this._killReserved ){ this.kill(); @@ -324,8 +334,10 @@ function X_EventDispatcher_dispatch( e ){ for( i = 0, l = list.length; i < l; ++i ){ f = list[ i ]; X_EventDispatcher_once = f[ 4 ]; + X_EventDispatcher_lock = f[ 5 ]; this.listen( f[ 0 ], f[ 1 ], f[ 2 ], f[ 3 ] ); X_EventDispatcher_once = false; + X_EventDispatcher_lock = false; f.length = 0; }; list.length = 0; @@ -339,19 +351,22 @@ function X_EventDispatcher_dispatch( e ){ /** * * @this {X.EventDispatcher} - * @return {X.EventDispatcher} + * @memberOf X.EventDispatcher.prototype * @param {(string|number|Array.<(string,number)>)} type * @param {(listener|function|Array)=} opt_arg1 * @param {(function|Array=} opt_arg2 * @param {Array=} opt_arg3 + * @return {X.EventDispatcher} */ function X_EventDispatcher_listen( type, opt_arg1, opt_arg2, opt_arg3 ){ var list = this._listeners, i, raw, add, f; + + if( !type ) return this; if( this._dispatching ){ if( !this._reserves ) this._reserves = []; - this._reserves[ this._reserves.length ] = [ type, opt_arg1, opt_arg2, opt_arg3, X_EventDispatcher_once ]; + this._reserves[ this._reserves.length ] = [ type, opt_arg1, opt_arg2, opt_arg3, X_EventDispatcher_once, X_EventDispatcher_lock ]; return this; }; @@ -362,23 +377,35 @@ function X_EventDispatcher_listen( type, opt_arg1, opt_arg2, opt_arg3 ){ return this; }; - raw = this._rawObject || this._ie4getRawNode && this._ie4getRawNode(); + raw = this._rawObject || X_UA_DOM.IE4 && X_Node__ie4getRawNode( this ); add = raw && ( !list || !list[ type ] ) && X.Type.isString( type ); - if( this.listening( type, opt_arg1, opt_arg2, opt_arg3 ) ) return this; + if( this.listening( type, opt_arg1 || this, opt_arg2, opt_arg3 ) ) return this; if( !list ) list = this._listeners = {}; if( !( list = list[ type ] ) ) list = this._listeners[ type ] = []; - add && X_EventDispatcher_actualAddEvent( this, type, raw, list ); + add && X_EventDispatcher_addEvent( this, type, raw, list ); - f = X.Callback._classifyCallbackArgs( opt_arg1, opt_arg2, opt_arg3, this ); + f = X_Callback_classifyCallbackArgs( opt_arg1, opt_arg2, opt_arg3, this ); list[ list.length ] = f; f.once = X_EventDispatcher_once; + f.lock = X_EventDispatcher_lock; return this; }; +/* + * X_EventDispatcher_systemUnlisten çµç±ã§ãªãã¨è§£é¤ã§ããªããªã¹ãã®ç»é² + */ +function X_EventDispatcher_systemListen( that, type, opt_arg1, opt_arg2, opt_arg3 ){ + X_EventDispatcher_lock = true; + that.listen( type, opt_arg1, opt_arg2, opt_arg3 ); + X_EventDispatcher_lock = false; +}; + +// TODO this.listen(type) 㯠this ãªã¹ãã®ç»é²ãªã®ã«ãthis.unlisten(type)ã¯å ¨ã¦ã®typeã®åé¤ãã¨ä¸ä¸è´ + /** * * @this {X.EventDispatcher} @@ -396,6 +423,9 @@ function X_EventDispatcher_unlisten( opt_type, opt_arg1, opt_arg2, opt_arg3 ){ if( X.Type.isArray( opt_type ) ){ for( i = opt_type.length; i; ){ this.unlisten( opt_type[ --i ], opt_arg1, opt_arg2, opt_arg3 ); + if( !opt_type[ i ] ){ + alert( 'ä¸æ£ãª unlisten Array' ); + }; }; return this; }; @@ -403,6 +433,7 @@ function X_EventDispatcher_unlisten( opt_type, opt_arg1, opt_arg2, opt_arg3 ){ if( opt_type === undefined ){ // å ¨ã¦åé¤ for( opt_type in list ){ + //if( X_EMPTY_OBJECT[ opt_type ] ) continue; _list = list[ opt_type ]; for( i = _list.length; i; ){ this.unlisten( opt_type, _list[ --i ] ); // override ããã¦ãããã¨ãããã®ã§ãå¿ ã unlisten ãä½¿ç¨ @@ -437,108 +468,127 @@ function X_EventDispatcher_unlisten( opt_type, opt_arg1, opt_arg2, opt_arg3 ){ if( i === false ) return this; f = ( _list = list[ opt_type ] )[ i ]; + // _unlistens ã«å ¥ã£ã¦ãã callbackHash ã¯ãlock ãã¯ãªã¢ãã¦ãã if( unlistens = this._unlistens ){ ( unlistens = unlistens[ opt_type ] ) ? ( unlistens[ unlistens.length ] = f ) : ( this._unlistens[ opt_type ] = [ f ] ); } else { delete f.once; - // f.kill === X.Callback._kill && f.kill(); _list.splice( i, 1 ); if( !_list.length ){ - raw = this._rawObject || this._ie4getRawNode && this._ie4getRawNode(); + raw = this._rawObject || X_UA_DOM.IE4 && X_Node__ie4getRawNode( this ); delete list[ opt_type ]; - if( empty = X.isEmptyObject( list ) ) delete this._listeners; + if( empty = X_Object_isEmpty( list ) ) delete this._listeners; if( raw && '' + parseFloat( opt_type ) !== '' + opt_type ){ // æ°åã¤ãã³ãã®é¤å¤ - X_EventDispatcher_actualRemoveEvent( this, opt_type, raw, _list, !empty ); + X_EventDispatcher_removeEvent( this, opt_type, raw, _list, !empty ); }; }; }; return this; }; +/* + * X_EventDispatcher_systemListen ããç»é²ããã¤ãã³ãã®è§£é¤ + */ +function X_EventDispatcher_systemUnlisten( that, type, opt_arg1, opt_arg2, opt_arg3 ){ + X_EventDispatcher_unlock = true; + that.unlisten( type, opt_arg1, opt_arg2, opt_arg3 ); + X_EventDispatcher_unlock = false; +}; + +function X_EventDispatcher_addEvent( that, type, raw, list ){ + var i; + X_EventDispatcher_lock || ( type = X_Event_Rename[ type ] || type ); + + if( X.Type.isArray( type ) ){ + for( i = type.length; i; ){ + X_EventDispatcher_systemListen( that, type[ --i ], X.emptyFunction ); + console.log( 'events fix > ' + type[ i ] ); + }; + } else { + X_EventDispatcher_actualAddEvent( that, type, raw, list ); + }; +}; var X_EventDispatcher_actualAddEvent = // Days on the Moon DOM Events ã¨ãã©ã¦ã¶ã®å®è£ // http://nanto.asablo.jp/blog/2007/03/23/1339502 // Safari 2 ã§ã¯é¢æ°ãªãã¸ã§ã¯ããã EventListener ã¨ãã¦ä½¿ãã¾ããããSafari ã®ãã¤ããªã¼ãã«ãã§ã¯ handleEvent ã¡ã½ãããæã¤ãªãã¸ã§ã¯ãã EventListener ã¨ãã¦ä½¿ããããã§ãã - X_EventDispatcher_temp.EVENT_W3C /* && ( X.UA.WebKit < 525.13 || X.UA.Opera7 || X.UA.NetFront < 4 ) */ ? // Safari3- + X_UA_EVENT.W3C /* && ( X_UA.WebKit < 525.13 || X_UA.Opera7 || X_UA.NetFront < 4 ) */ ? // Safari3- (function( that, type, raw, list ){ - var i; - - type = X.Dom.Event.Rename[ type ] || type; - - if( X.Type.isArray( type ) ){ - for( i = type.length; i; ){ - X_EventDispatcher_actualAddEvent( that, type[ --i ], raw, list ); - }; + if( that._isXHR && X_UA.Opera < 12 ){ + // Opera11- ã® XHR 㯠event ãªãã¸ã§ã¯ããè¿ããªããã, eventType æ¯ã« callback ãæå®ãã addEventListener ããªã + raw[ 'on' + type ] = X_Callback_create( that, X_EventDispatcher_dispatch, [ type ] ); + } else + if( that._isSilverlight ){ + list.slcallback = X_Callback_create( that, X_EventDispatcher_sliverLightDispatch, [ type ] ); + list.sltoken = raw.AddEventListener( type, list.slcallback ); + } else + // iOS 㨠MacOSX Iron36 ã§çºçãé£ç¶ãã¦ã¢ãã¡ã¼ã·ã§ã³ãèµ·ããã¨ãã¯ãã¼ã¸ã£ã®æç¸ããã obj ã¸ã®ã¢ã¯ã»ã¹ã«å¤±æãããWin ã§ã¯èµ·ããªã? + // ããããMacOSX ã®ãã©ã¦ã¶å ¨è¬ã§èµ·ãã?? + if( ( X_UA.WebKit || X_UA.Blink ) && + ( type === 'webkitTransitionEnd' || type === 'transitionend' || + type === 'animationend' || type === 'webkitAnimationEnd' || + type === 'animationstart' || type === 'webkitAnimationStart' || + type === 'animationiteration' || type === 'webkitAnimationIteration' ) ){ + raw.addEventListener( type, X_EventDispatcher_iOSTransitionEndDispatch, false ); } else { - that._handleEvent || ( that._handleEvent = X.Callback.create( that, X_EventDispatcher_actualHandleEvent ) ); - - if( that._isSilverlight ){ - list.slcallback = X.Callback.create( that, X_EventDispatcher_sliverLightDispatch, [ type ] ); - list.sltoken = raw.AddEventListener( type, list.slcallback ); - } else + console.log( 'event > ' + type ); + that._handleEvent || ( that._handleEvent = X_Callback_create( that, X_EventDispatcher_actualHandleEvent ) ); + if( raw.addEventListener ){ raw.addEventListener( type, that._handleEvent, false ); } else { // Safari 㯠Image, Opera7 㯠window raw[ 'on' + type ] = that._handleEvent; - }; + }; }; }) : - X_EventDispatcher_temp.EVENT_IE ? + X_UA_EVENT.IE ? (function( that, type, raw, list ){ - var i; - //if( type === 'load' && that._tag && X.Dom.Event._LOAD_FIX_TAGS[ that._tag ] ){ - // type = 'readystatechange'; - //}; if( that._isXHR ){ // ie8- ã® XHR 㯠window.event ãæ´æ°ãããªããã, eventType æ¯ã« callback ãæå®ãã - raw[ 'on' + type ] = X.Callback.create( that, X_EventDispatcher_dispatch, [ type ] ); - } else { - type = X.Dom.Event.Rename[ type ] || type; + raw[ 'on' + type ] = X_Callback_create( that, X_EventDispatcher_dispatch, [ type ] ); + } else + if( that._isSilverlight ){ + list.slcallback = X_Callback_create( that, X_EventDispatcher_sliverLightDispatch, [ type ] ); + list.sltoken = raw.AddEventListener( type, list.slcallback ); + } else { + that._handleEvent || ( that._handleEvent = X_Callback_create( that, X_EventDispatcher_actualHandleEvent ) ); - if( X.Type.isArray( type ) ){ - for( i = type.length; i; ){ - X_EventDispatcher_actualAddEvent( that, type[ --i ], raw, list ); - }; - } else{ - that._handleEvent || ( that._handleEvent = X.Callback.create( that, X_EventDispatcher_actualHandleEvent ) ); - - if( that._isSilverlight ){ - list.slcallback = X.Callback.create( that, X_EventDispatcher_sliverLightDispatch, [ type ] ); - list.sltoken = raw.AddEventListener( type, list.slcallback ); - } else - if( raw.attachEvent ){ - raw.attachEvent( 'on' + type, that._handleEvent ); - } else { - raw[ 'on' + type ] = that._handleEvent; - }; - }; + if( raw.attachEvent ){ + raw.attachEvent( 'on' + type, that._handleEvent ); + } else { + raw[ 'on' + type ] = that._handleEvent; + }; }; }) : (function( that, type, raw, list ){ - var i; - type = X.Dom.Event.Rename[ type ] || type; - - if( X.Type.isArray( type ) ){ - for( i = type.length; i; ){ - X_EventDispatcher_actualAddEvent( that, type[ --i ], raw, list ); - }; + if( that._isXHR ){ + // ie4 mobile 㯠XHR ããµãã¼ãï¼ + raw[ 'on' + type ] = X_Callback_create( that, X_EventDispatcher_dispatch, [ type ] ); + } else + if( that._isSilverlight ){ + // DOM0 㧠Silverlight ã£ã¦ããã®? + list.slcallback = X_Callback_create( that, X_EventDispatcher_sliverLightDispatch, [ type ] ); + list.sltoken = raw.AddEventListener( type, list.slcallback ); } else { - that._handleEvent || ( that._handleEvent = X.Callback.create( that, X_EventDispatcher_actualHandleEvent ) ); - - if( that._isSilverlight ){ - list.slcallback = X.Callback.create( that, X_EventDispatcher_sliverLightDispatch, [ type ] ); - list.sltoken = raw.AddEventListener( type, list.slcallback ); - } else { - raw[ 'on' + type ] = that._handleEvent; - }; + raw[ 'on' + type ] = that._handleEvent || ( that._handleEvent = X_Callback_create( that, X_EventDispatcher_actualHandleEvent ) ); }; }); /* + * iOS ã® webkitTransitionEnd ãé£ç¶ãã¦èµ·ããå ´åã + * ã³ã¼ã«ããã¯ã®(that._handleEvent)ã¯ãã¼ã¸ã£å ã®å®éã®ã³ã¼ã«ããã¯(X_Callback_actualClosure:obj._)ã + * åç §ã§ãã¦ããªãåé¡ã«ééãããiOS3.1.3 & iOS6.1.5 ã§ç¢ºèª + * animation ãæªããããã + */ +function X_EventDispatcher_iOSTransitionEndDispatch( e ){ + return X_Node_getXNode( this ).dispatch( X_Event_RenameTo[ e.type ] || e.type ); +}; + +/* * Silverlight ã®ã¤ãã³ãã®æ¦è¦ * http://msdn.microsoft.com/ja-jp/library/cc189018%28v=vs.95%29.aspx#the_sender_parameter_and_event_data */ @@ -546,97 +596,95 @@ function X_EventDispatcher_sliverLightDispatch( sender, e, type ){ return this.dispatch( type ); }; +function X_EventDispatcher_removeEvent( that, type, raw, list, skip ){ + var i; + X_EventDispatcher_unlock || ( type = X_Event_Rename[ type ] || type ); + + if( X.Type.isArray( type ) ){ + for( i = type.length; i; ){ + X_EventDispatcher_systemUnlisten( that, type[ --i ], X.emptyFunction ); + }; + } else { + X_EventDispatcher_actualRemoveEvent( that, type, raw, list, skip ); + }; +}; + var X_EventDispatcher_actualRemoveEvent = - X_EventDispatcher_temp.EVENT_W3C /*&& ( X.UA.WebKit < 525.13 || X.UA.Opera7 || X.UA.NetFront < 4 )*/ ? // Safari3- + X_UA_EVENT.W3C /*&& ( X_UA.WebKit < 525.13 || X_UA.Opera7 || X_UA.NetFront < 4 )*/ ? // Safari3- (function( that, type, raw, list, skip ){ - type = X.Dom.Event.Rename[ type ] || type; - - if( X.Type.isArray( type ) ){ - for( i = type.length; i; ){ - X_EventDispatcher_actualRemoveEvent( that, type[ --i ], raw, list, i ? true : skip ); - }; + if( that._isXHR && X_UA.Opera < 12 ){ + X_Callback_correct( raw[ 'on' + type ] ); + raw[ 'on' + type ] = ''; + } else + if( that._isSilverlight ){ + raw.RemoveEventListener( type, list.sltoken ); // token + X_Callback_correct( list.slcallback ); + delete list.sltoken; + delete list.slcallback; + } else + if( ( X_UA.WebKit || X_UA.Blink ) && + ( type === 'webkitTransitionEnd' || type === 'transitionend' || + type === 'animationend' || type === 'webkitAnimationEnd' || + type === 'animationstart' || type === 'webkitAnimationStart' || + type === 'animationiteration' || type === 'webkitAnimationIteration' ) ){ + raw.removeEventListener( type, X_EventDispatcher_iOSTransitionEndDispatch, false ); } else { - - if( that._isSilverlight ){ - raw.RemoveEventListener( type, list.sltoken ); // token - X.Callback._correct( list.slcallback ); - delete list.sltoken; - delete list.slcallback; + + if( raw.addEventListener ){ + raw.removeEventListener( type, that._handleEvent, false ); } else { - if( raw.addEventListener ){ - raw.removeEventListener( type, that._handleEvent, false ); - } else { - raw[ 'on' + type ] = null; - }; - if( !skip ){ - X.Callback._correct( that._handleEvent ); - delete that._handleEvent; - }; + raw[ 'on' + type ] = null; + }; + if( !skip ){ + X_Callback_correct( that._handleEvent ); + delete that._handleEvent; }; }; }) : - X_EventDispatcher_temp.EVENT_IE ? + X_UA_EVENT.IE ? (function( that, type, raw, list, skip ){ - var i; - //if( type === 'load' && that._tag && X.Dom.Event._LOAD_FIX_TAGS[ that._tag ] ){ - // type = 'readystatechange'; - //}; if( that._isXHR ){ - X.Callback._correct( raw[ 'on' + type ] ); + X_Callback_correct( raw[ 'on' + type ] ); raw[ 'on' + type ] = X.emptyFunction; raw[ 'on' + type ] = ''; + } else + if( that._isSilverlight ){ + raw.RemoveEventListener( type, list.sltoken ); // token + X_Callback_correct( list.slcallback ); + delete list.sltoken; + delete list.slcallback; } else { - type = X.Dom.Event.Rename[ type ] || type; - - if( X.Type.isArray( type ) ){ - for( i = type.length; i; ){ - X_EventDispatcher_actualRemoveEvent( that, type[ --i ], raw, list, i ? true : skip ); - }; + if( raw.attachEvent ){ + raw.detachEvent( 'on' + type, that._handleEvent ); } else { - - if( that._isSilverlight ){ - raw.RemoveEventListener( type, list.sltoken ); // token - X.Callback._correct( list.slcallback ); - delete list.sltoken; - delete list.slcallback; - } else { - if( raw.attachEvent ){ - raw.detachEvent( 'on' + type, that._handleEvent ); - } else { - raw[ 'on' + type ] = X.emptyFunction; - raw[ 'on' + type ] = ''; - }; - - if( !skip ){ - X.Callback._correct( that._handleEvent ); - delete that._handleEvent; - }; - }; + raw[ 'on' + type ] = X.emptyFunction; + raw[ 'on' + type ] = ''; + }; + + if( !skip ){ + X_Callback_correct( that._handleEvent ); + delete that._handleEvent; }; }; }) : (function( that, type, raw, list, skip ){ - var i; - type = X.Dom.Event.Rename[ type ] || type; - if( X.Type.isArray( type ) ){ - for( i = type.length; i; ){ - X_EventDispatcher_actualRemoveEvent( that, type[ --i ], raw, list, i ? true : skip ); - }; + if( that._isXHR ){ + X_Callback_correct( raw[ 'on' + type ] ); + raw[ 'on' + type ] = X.emptyFunction; + raw[ 'on' + type ] = ''; + } else + if( that._isSilverlight ){ + raw.RemoveEventListener( type, list.sltoken ); // token + X_Callback_correct( list.slcallback ); + delete list.sltoken; + delete list.slcallback; } else { + raw[ 'on' + type ] = X.emptyFunction; + raw[ 'on' + type ] = ''; - if( that._isSilverlight ){ - raw.RemoveEventListener( type, list.sltoken ); // token - X.Callback._correct( list.slcallback ); - delete list.sltoken; - delete list.slcallback; - } else { - raw[ 'on' + type ] = X.emptyFunction; - raw[ 'on' + type ] = ''; - - if( !skip ){ - X.Callback._correct( that._handleEvent ); - delete that._handleEvent; - }; + if( !skip ){ + X_Callback_correct( that._handleEvent ); + delete that._handleEvent; }; }; }); @@ -646,7 +694,7 @@ var X_EventDispatcher_actualRemoveEvent = // Is this in regard to the Safari 1.x preventDefault bug on click/dblclick? // https://groups.google.com/forum/#!msg/comp.lang.javascript/uYEuCHjHxnw/yKoHtZJPa1QJ var X_EventDispatcher_actualHandleEvent = - X.UA.IE4 || X_EventDispatcher_temp.EVENT_IE ? // ie45678 EVENT_IE & EVENT_DOM0 for ie4 + X_UA_EVENT.IE4 || X_UA_EVENT.IE ? // ie45678 EVENT_IE & EVENT_DOM0 for ie4 (function(){ var ret; @@ -664,12 +712,12 @@ var X_EventDispatcher_actualHandleEvent = return event.returnValue = false; }; }) : - //X.Dom.EVENT_W3C & EVENT_DOM0 + //X_UA_EVENT.W3C & X_UA_EVENT.DOM0 (function( e ){ var ev = new X.Dom.Event( e, this ), - ret = X.Callback.NONE, + ret = X_Callback_NONE, i, l; - + //console.log( '>>>>>>>>>> ' + e.type ); // touch event -> pointer if( X.Type.isArray( ev ) ){ if( ev.length === 0 ){ @@ -677,6 +725,7 @@ var X_EventDispatcher_actualHandleEvent = ret = X.Callback.STOP_PROPAGATION | X.Callback.PREVENT_DEFAULT; } else { for( i = 0, l = ev.length; i < l; ++i ){ + console.log( 'handleEvent ' + ev[ i ].type ); ret |= this.dispatch( ev[ i ] ) || 0; }; }; @@ -690,7 +739,7 @@ var X_EventDispatcher_actualHandleEvent = if( ret & X.Callback.PREVENT_DEFAULT ){ this._tag === 'A' && this._rawObject.blur(); e.preventDefault(); - if( X.UA.WebKit < 525.13 ){ // Safari3- + if( X_UA.WebKit < 525.13 ){ // Safari3- if( e.type === 'click' || e.type === 'dbclick' ){ X_EventDispatcher_safariPreventDefault = true; }; @@ -699,7 +748,7 @@ var X_EventDispatcher_actualHandleEvent = }; }); -if( X.UA.WebKit < 525.13 ){ // Safari3- +if( X_UA.WebKit < 525.13 ){ // Safari3- document.documentElement.onclick = document.documentElement.ondbclick = function( e ){ if( X_EventDispatcher_safariPreventDefault ){ @@ -714,13 +763,15 @@ if( X.UA.WebKit < 525.13 ){ // Safari3- // éé¿ããã¤ãã³ãã®å¾©å¸° function X_EventDispatcher_toggleAllEvents( that, add ){ var list = that._listeners, - raw = that._rawObject || that._ie4getRawNode && that._ie4getRawNode(), - f = add ? X_EventDispatcher_actualAddEvent : X_EventDispatcher_actualRemoveEvent, + raw = that._rawObject || X_UA_DOM.IE4 && X_Node__ie4getRawNode( that ), + f = add ? X_EventDispatcher_addEvent : X_EventDispatcher_removeEvent, type; if( !list || !raw ) return; for( type in list ){ + //if( X_EMPTY_OBJECT[ type ] ) continue; // æ°åã¤ãã³ãã®é¤å¤ if( '' + parseFloat( type ) !== type ){ + // TODO type rename ã¯ãã f( that, type, raw, list[ type ], true ); }; };