X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F01_core%2F15_XEventDispatcher.js;h=5a9864a7c49128ef149c81b9cfc1d2461e8261b8;hb=a205577d1e16a34301f1199dcf9c699aa2c37fb9;hp=699c34b47b66774b7a06b8fa61251a85e58001ec;hpb=f24f3611a2525a2a4751a02aead9d3f69bb115d0;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/01_core/15_XEventDispatcher.js b/0.6.x/js/01_core/15_XEventDispatcher.js index 699c34b..5a9864a 100644 --- a/0.6.x/js/01_core/15_XEventDispatcher.js +++ b/0.6.x/js/01_core/15_XEventDispatcher.js @@ -36,22 +36,27 @@ var X_LISTENERS_ACTUAL_HANDLER = 0, // ------------------------------------------------------------------------- // // ------------ local variables -------------------------------------------- // // ------------------------------------------------------------------------- // +var X_EventDispatcher_EVENT_TARGET_OTHER = 0, + X_EventDispatcher_EVENT_TARGET_XHR = 1, + X_EventDispatcher_EVENT_TARGET_SILVER_LIGHT = 2; -var X_EventDispatcher_once = false, - X_EventDispatcher_lock = false, - X_EventDispatcher_unlock = false, - X_EventDispatcher_needsIndex = false, +var X_EventDispatcher_once = false, + X_EventDispatcher_lock = false, + X_EventDispatcher_unlock = false, + X_EventDispatcher_needsIndex = false, X_EventDispatcher_safariPreventDefault = false, // Safari3- + + X_EventDispatcher_LAZY_TIMERS = {},// Object. number は timerID - /* @const */ - X_EventDispatcher_EVENT_TARGET_OTHER = 0, - /* @const */ - X_EventDispatcher_EVENT_TARGET_XHR = 1, - /* @const */ - X_EventDispatcher_EVENT_TARGET_SILVER_LIGHT = 2, - - X_EventDispatcher_LAZY_TIMERS = {}; // Object. number は timerID + // iOS と MacOSX Iron36 で発生。連続してアニメーションが起こると、クロージャの束縛された obj へのアクセスに失敗する。Win では起きない? + // むしろ、MacOSX のブラウザ全般で起こる?? + X_EventDispatcher_ANIME_EVENTS = ( X_UA[ 'WebKit' ] || X_UA[ 'Blink' ] ) && { + 'transitionend' : true, 'webkitTransitionEnd' : true, 'mozTransitionEnd' : true, 'oTransitionEnd' : true, 'otransitionEnd' : true, + 'animationend' : true, 'webkitAnimationEnd' : true, 'oAnimationEnd' : true, + 'animationstart' : true, 'webkitAnimationStart' : true, 'oAnimationStart' : true, + 'animationiteration' : true, 'webkitAnimationIteration' : true, 'oAnimationIteration' : true + }; // ------------------------------------------------------------------------- // // --- interface ----------------------------------------------------------- // @@ -93,7 +98,9 @@ var X_EventDispatcher = X[ 'EventDispatcher' ] = { /** - * OTHER(Node,window,document,Image,Audio), XHR, Silverlight + * EventDispatcher がラップしている EventTarget オブジェクトのタイプです。
+ * X_EventDispatcher_actualAddEvent で使用されます。
+ * OTHER:0(node,window,document,Image,Audio), XHR:1, Silverlight:2 * @private * @type {number} */ @@ -366,10 +373,6 @@ function X_EventDispatcher_dispatch( e ){ * this[ 'listen' ]( [ 'open', 'close', 'ready' ], onUpdate ); * * @alias EventDispatcher.prototype.listen - * @param {string|number|Array.} type 配列を指定した場合、複数のイベントタイプに対して同じコールバックを登録する。 - * @param {listener|function|Array} [opt_arg1=] - * @param {function|Array} [opt_arg2=] - * @param {Array} [opt_arg3=] コールバック時の引数を配列に入れる。引数がひとつでも配列を使用する。省略した場合引数なし。 * @return {EventDispatcher} チェインメソッド */ function X_EventDispatcher_listen( type, opt_arg1, opt_arg2, opt_arg3 ){ @@ -419,13 +422,10 @@ function X_EventDispatcher_systemListen( that, type, opt_arg1, opt_arg2, opt_arg }; /** - * イベントリスナの解除を行う。登録時と同じ引数を与える必要がある。kill() ですべてのイベントが解除されるので、途中で解除されるイベント以外は kill() に任せてしまってよい。 + * イベントリスナの解除を行う。登録時と同じ引数を与える必要がある。kill() で自信に登録されたすべてのイベントが解除されるので、途中で解除されるイベント以外は kill() に任せてしまってよい。
+ * 他人に登録したイベントを解除せずに kill するのは NG。 * @alias EventDispatcher.prototype.unlisten * @return {EventDispatcher} - * @param {string|number|Array.} opt_type イベントID, イベント名、またはその配列 - * @param {listener|function|Array} opt_arg1 - * @param {function|Array} opt_arg2 - * @param {Array} opt_arg3 */ function X_EventDispatcher_unlisten( opt_type, opt_arg1, opt_arg2, opt_arg3 ){ var listeners = this[ '_listeners' ], @@ -524,6 +524,7 @@ function X_EventDispatcher_unlistenAll( that ){ function X_EventDispatcher_actualAddEvent( that, type, raw, list ){ var i, f; + X_EventDispatcher_lock || ( type = X_Event_Rename[ type ] || type ); if( X_Type_isArray( type ) ){ @@ -552,13 +553,7 @@ function X_EventDispatcher_actualAddEvent( that, type, raw, list ){ }; default : - // 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' ) ){ + if( X_EventDispatcher_ANIME_EVENTS && X_EventDispatcher_ANIME_EVENTS[ type ] ){ raw.addEventListener( type, X_EventDispatcher_iOSTransitionEndDispatch, false ); } else { f = that[ '_listeners' ][ X_LISTENERS_ACTUAL_HANDLER ] || ( that[ '_listeners' ][ X_LISTENERS_ACTUAL_HANDLER ] = X_Closure_create( that, X_EventDispatcher_actualHandleEvent ) ); @@ -637,6 +632,7 @@ function X_EventDispatcher_sliverLightDispatch( sender, e, type ){ function X_EventDispatcher_actualRemoveEvent( that, type, raw, list, skip ){ var i; + X_EventDispatcher_unlock || ( type = X_Event_Rename[ type ] || type ); if( X_Type_isArray( type ) ){ @@ -662,13 +658,9 @@ function X_EventDispatcher_actualRemoveEvent( that, type, raw, list, skip ){ }; default : - if( ( X_UA[ 'WebKit' ] || X_UA[ 'Blink' ] ) && - ( type === 'webkitTransitionEnd' || type === 'transitionend' || - type === 'animationend' || type === 'webkitAnimationEnd' || - type === 'animationstart' || type === 'webkitAnimationStart' || - type === 'animationiteration' || type === 'webkitAnimationIteration' ) ){ + if( X_EventDispatcher_ANIME_EVENTS && X_EventDispatcher_ANIME_EVENTS[ type ] ){ raw.removeEventListener( type, X_EventDispatcher_iOSTransitionEndDispatch, false ); - } else + } else if( raw.addEventListener ){ raw.removeEventListener( type, that[ '_listeners' ][ X_LISTENERS_ACTUAL_HANDLER ], false ); } else { @@ -741,6 +733,7 @@ function X_EventDispatcher_actualRemoveEvent( that, type, raw, list, skip ){ // TODO ブラウザからの呼び出しの最後に登録された関数を呼び出す機能(例えば画面の更新) +var X_EventDispatcher_CURRENT_EVENTS = []; // handleEvent を拡張可能にするために、クロージャに移動した // Is this in regard to the Safari 1.x preventDefault bug on click/dblclick? @@ -748,9 +741,14 @@ function X_EventDispatcher_actualRemoveEvent( that, type, raw, list, skip ){ var X_EventDispatcher_actualHandleEvent = X_UA_EVENT.IE4 || X_UA_EVENT.IE ? // ie45678 EVENT_IE & EVENT_DOM0 for ie4 (function(){ - var e = event, ret; + var e = event, ret, + ev = new X_DomEvent( e, this, this[ '_rawObject' ] ); + + X_EventDispatcher_CURRENT_EVENTS[ X_EventDispatcher_CURRENT_EVENTS.length ] = ev; - ret = this[ 'dispatch' ]( new X_DomEvent( e, this, this[ '_rawObject' ] ) ); + ret = this[ 'dispatch' ]( ev ); + + --X_EventDispatcher_CURRENT_EVENTS.length; if( ret & X_CALLBACK_STOP_PROPAGATION ){ e.cancelBubble = true; @@ -765,7 +763,9 @@ var X_EventDispatcher_actualHandleEvent = var ev = new X_DomEvent( e, this ), ret = X_CALLBACK_NONE, i, l; - //console.log( '>>>>>>>>>> ' + e.type ); + + X_EventDispatcher_CURRENT_EVENTS[ X_EventDispatcher_CURRENT_EVENTS.length ] = ev; + // touch event -> pointer if( X_Type_isArray( ev ) ){ if( ev.length === 0 ){ @@ -781,6 +781,8 @@ var X_EventDispatcher_actualHandleEvent = ret = this[ 'dispatch' ]( ev ); }; + --X_EventDispatcher_CURRENT_EVENTS.length; + if( ret & X_CALLBACK_STOP_PROPAGATION ){ e.stopPropagation(); };