OSDN Git Service

Version 0..6.127, commitUpdate after GPU_RELEASED.
[pettanr/clientJs.git] / 0.6.x / js / 01_core / 13_XEventDispatcher.js
index 1ae7244..25c2d11 100644 (file)
@@ -76,7 +76,7 @@ X.EventDispatcher =
                 * _rawObject には HTMLElement, window, document, XHR といったイベントターゲットオブジェクトを設定します。\r
                 * _rawObject が設定されていると listen(), unlisten() 時に addEventListener(DOM Level2) や detachEvent(ie5~8), on~(DOM0) 等を操作します。\r
                 * _rawObject は最初の listen() 前に設定しておかないと addEventListener 等が意図したように行われません。\r
-                * X.Node では非同期に HTMLElement を生成していて、要素生成以前に on, off を呼び出すことができます。これは適宜に migrateEvent, restoreEvent を呼んで解決しているためです。\r
+                * X.Node では非同期に HTMLElement を生成していて、要素生成以前に listen, unlisten を呼び出すことができます。これは適宜に X_EventDispatcher_toggleAllEvents を呼んで解決しているためです。\r
                 * @private\r
                 * @type {Object}\r
                 */\r
@@ -120,6 +120,14 @@ X.EventDispatcher =
                 * @type {boolean}\r
                 */\r
                        '_killReserved' : false,\r
+\r
+               /**\r
+                * asyncDispatch 中に kill が呼ばれた場合に、X.EventDispatcher インスタンスの削除を最後のタイマーの発火後にずらすために立てるフラグ。\r
+                * TODO asyncDispatch の解除はどうする?\r
+                * @private\r
+                * @type {boolean}\r
+                */\r
+                       '_lastLazyID' : false,\r
                        \r
            /**\r
             * X.EventDispatcher のコンストラクタの実体。\r
@@ -229,7 +237,7 @@ X.EventDispatcher =
                                        e = delay;\r
                                        delay = 0;\r
                                };\r
-                               return X.Timer.add( delay, 1, this, this.dispatch, [ e ] );\r
+                               return this[ '_lastLazyID' ] = X.Timer.add( delay, 1, this, X_EventDispatcher_dispatch, [ e ] );\r
                        }\r
                }\r
        );\r
@@ -297,6 +305,11 @@ function X_EventDispatcher_dispatch( e ){
        };\r
        \r
        if( ( --this._dispatching ) === 0 ){\r
+               \r
+               if( this[ '_lastLazyID' ] && X_Timer_currentUID === this[ '_lastLazyID' ] ){\r
+                       delete this[ '_lastLazyID' ];\r
+               };\r
+               \r
                // dispatch 中に unlisten された要素の削除\r
                unlistens = this._unlistens;\r
                delete this._dispatching;\r
@@ -304,6 +317,7 @@ function X_EventDispatcher_dispatch( e ){
                // _unlistens に入っている callbackHash は、lock をクリアしている\r
                X_EventDispatcher_unlock = true;\r
                for( type in unlistens ){\r
+                       //if( X_EMPTY_OBJECT[ type ] ) continue;\r
                        list = unlistens[ type ];\r
                        for( i = list.length; i; ){\r
                                this.unlisten( type, list[ --i ] );\r
@@ -419,6 +433,7 @@ function X_EventDispatcher_unlisten( opt_type, opt_arg1, opt_arg2, opt_arg3 ){
        if( opt_type === undefined ){\r
                // 全て削除\r
                for( opt_type in list ){\r
+                       //if( X_EMPTY_OBJECT[ opt_type ] ) continue;\r
                        _list = list[ opt_type ];\r
                        for( i = _list.length; i; ){\r
                                this.unlisten( opt_type, _list[ --i ] ); // override されていることがあるので、必ず unlisten を使用\r
@@ -510,12 +525,17 @@ var X_EventDispatcher_actualAddEvent =
                                list.slcallback = X_Callback_create( that, X_EventDispatcher_sliverLightDispatch, [ type ] );\r
                                list.sltoken    = raw.AddEventListener( type, list.slcallback );\r
                        } else\r
-                       if( X.UA.iOS && ( type === 'webkitTransitionEnd' || type === 'transitionend' ) ){\r
+                       // iOS と MacOSX Iron36 で発生。連続してアニメーションが起こると、クロージャの束縛された obj へのアクセスに失敗する。Win では起きない?\r
+                       // むしろ、MacOSX のブラウザ全般で起こる??\r
+                       if( ( X_UA.WebKit || X_UA.Blink ) &&\r
+                               ( type === 'webkitTransitionEnd' || type === 'transitionend' ||\r
+                                 type === 'animationend'        || type === 'webkitAnimationEnd' ||\r
+                                 type === 'animationstart'      || type === 'webkitAnimationStart' ||\r
+                                 type === 'animationiteration'  || type === 'webkitAnimationIteration' ) ){\r
                                raw.addEventListener( type, X_EventDispatcher_iOSTransitionEndDispatch, false );\r
                        } else {\r
                                console.log( 'event > ' + type );\r
                                that._handleEvent || ( that._handleEvent = X_Callback_create( that, X_EventDispatcher_actualHandleEvent ) );\r
-                               \r
 \r
                                if( raw.addEventListener ){\r
                                        raw.addEventListener( type, that._handleEvent, false );\r
@@ -565,7 +585,7 @@ var X_EventDispatcher_actualAddEvent =
  * animation も怪しい、、、\r
  */\r
 function X_EventDispatcher_iOSTransitionEndDispatch( e ){\r
-       return X_Node_getXNode( this ).dispatch( X_Event_RenameTo[ e.type ] );\r
+       return X_Node_getXNode( this ).dispatch( X_Event_RenameTo[ e.type ] || e.type );\r
 };\r
 \r
 /*\r
@@ -602,7 +622,11 @@ var X_EventDispatcher_actualRemoveEvent =
                                delete list.sltoken;\r
                                delete list.slcallback;\r
                        } else\r
-                       if( X.UA.iOS && ( type === 'webkitTransitionEnd' || type === 'transitionend' ) ){\r
+                       if( ( X_UA.WebKit || X_UA.Blink ) &&\r
+                               ( type === 'webkitTransitionEnd' || type === 'transitionend' ||\r
+                                 type === 'animationend'        || type === 'webkitAnimationEnd' ||\r
+                                 type === 'animationstart'      || type === 'webkitAnimationStart' ||\r
+                                 type === 'animationiteration'  || type === 'webkitAnimationIteration' ) ){\r
                                raw.removeEventListener( type, X_EventDispatcher_iOSTransitionEndDispatch, false );\r
                        } else {\r
                                                                \r
@@ -744,6 +768,7 @@ function X_EventDispatcher_toggleAllEvents( that, add ){
                type;\r
        if( !list || !raw ) return;\r
        for( type in list ){\r
+               //if( X_EMPTY_OBJECT[ type ] ) continue;\r
                // 数字イベントの除外\r
                if( '' + parseFloat( type ) !== type ){\r
                        // TODO type rename はここ\r