X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F01_core%2F13_XEventDispatcher.js;h=25c2d11477034a160a6fcb231065e418636740b8;hb=9a3ec59dd9eafb9fde293ee2f112e168af1e62bc;hp=7ff83b395829e665c588d390456f0cd0d726b519;hpb=dd02887497fa95f13d112b7fc2e5e7aefd0ffb08;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 7ff83b3..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 ã©ã¤ã¯ãªã¯ã©ã¹ããã®ã¾ã¾ä½¿ã£ãããç¶æ¿ããããã³ã¼ã«ããã¯ä¸ã«ã¤ãã³ãã追å ãããï¼åé¤ãããï¼ã«ã対å¦ãã¦ããã @@ -32,30 +36,32 @@ var X_EventDispatcher_once = false, // ------------------------------------------------------------------------- // /** - * ã¤ãã³ãã¿ã¼ã²ãã(widnow, document, Image, XHR, Silverlight ç)ãã©ããããå ´åãé常ã¯ã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 ã«ãªãã¾ãã - * unlisten() ã¯ãå¼æ°ãæå®ããªãã£ãå ´åãå ¨ã¦ã®ã¤ãã³ãã解é¤ãã¾ãããã ããsystemListen çµç±ã§ç»é²ããããã³ãã©ã¯è§£é¤ããã¾ããã + *
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 ã¯ãã©ã¤ãã©ãªå ã®ã³ã¼ãããããã¢ã¯ã»ã¹ã§ãã¾ããã - * @param {object=} opt_rawObject + * + * @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, ... /** @@ -68,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.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} */ @@ -84,7 +90,7 @@ X.EventDispatcher = */ '_handleEvent' : null, - /* + /** * dispatch ä¸ã« dispatch ãå¼ã°ããéã«ããã®ãã¹ãã®æ·±ããä¿åããã * dispatch() çµäºæã« _dispatching ã 0 ã®å ´åã«ãç¾å¨ã®ã¤ã³ã¹ã¿ã³ã¹ã® dispatch ããã¹ã¦çµãã£ããã¨ã«ãªãã * @private @@ -92,7 +98,7 @@ X.EventDispatcher = */ '_dispatching' : 0, // dispatch ä¸ã® unlisten ã§ä½¿ç¨ - /* + /** * dispatch ä¸ã« listen ãå¼ã°ããå ´åã«ãé åã®indexãããããã¨ãé¿ãããããä¸æ¦ä¿æããã * _dispatching ã 0 ã®ã¨ãã« _reserves ã使ã£ã¦ listen() ãå¼ã³åºãã * @private @@ -100,7 +106,7 @@ X.EventDispatcher = */ '_reserves' : null, - /* + /** * dispatch ä¸ã« unlisten ãå¼ã°ããå ´åã«ãé åã®indexãããããã¨ãé¿ãããããä¸æ¦ä¿æããã * _dispatching ã 0 ã®ã¨ãã« _unlistens ã使ã£ã¦ unlisten() ãå¼ã³åºãã * @private @@ -108,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 ){ @@ -134,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, /** @@ -157,17 +175,19 @@ 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 @@ -217,7 +237,7 @@ X.EventDispatcher = e = delay; delay = 0; }; - return X.Timer.add( delay, 1, this, this.dispatch, [ e ] ); + return this[ '_lastLazyID' ] = X.Timer.add( delay, 1, this, X_EventDispatcher_dispatch, [ e ] ); } } ); @@ -285,6 +305,11 @@ 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; @@ -292,6 +317,7 @@ function X_EventDispatcher_dispatch( e ){ // _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 ] ); @@ -325,11 +351,12 @@ 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, @@ -406,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 ãä½¿ç¨ @@ -476,7 +504,7 @@ function X_EventDispatcher_addEvent( that, type, raw, list ){ if( X.Type.isArray( type ) ){ for( i = type.length; i; ){ X_EventDispatcher_systemListen( that, type[ --i ], X.emptyFunction ); - console.log( 'X_EventDispatcher_systemListen ' + type[ i ] ); + console.log( 'events fix > ' + type[ i ] ); }; } else { X_EventDispatcher_actualAddEvent( that, type, raw, list ); @@ -496,7 +524,17 @@ var X_EventDispatcher_actualAddEvent = if( that._isSilverlight ){ list.slcallback = X_Callback_create( that, X_EventDispatcher_sliverLightDispatch, [ type ] ); list.sltoken = raw.AddEventListener( type, list.slcallback ); - } else { + } 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 { + console.log( 'event > ' + type ); that._handleEvent || ( that._handleEvent = X_Callback_create( that, X_EventDispatcher_actualHandleEvent ) ); if( raw.addEventListener ){ @@ -541,6 +579,16 @@ var X_EventDispatcher_actualAddEvent = }); /* + * 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 */ @@ -573,7 +621,15 @@ var X_EventDispatcher_actualRemoveEvent = 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( raw.addEventListener ){ raw.removeEventListener( type, that._handleEvent, false ); } else { @@ -661,7 +717,7 @@ var X_EventDispatcher_actualHandleEvent = var ev = new X.Dom.Event( e, this ), ret = X_Callback_NONE, i, l; - console.log( '>>>>>>>>>> ' + e.type ); + //console.log( '>>>>>>>>>> ' + e.type ); // touch event -> pointer if( X.Type.isArray( ev ) ){ if( ev.length === 0 ){ @@ -712,6 +768,7 @@ function X_EventDispatcher_toggleAllEvents( that, add ){ type; if( !list || !raw ) return; for( type in list ){ + //if( X_EMPTY_OBJECT[ type ] ) continue; // æ°åã¤ãã³ãã®é¤å¤ if( '' + parseFloat( type ) !== type ){ // TODO type rename ã¯ãã