From 24f935c7a129b0a00d800e4983da6491a913aeef Mon Sep 17 00:00:00 2001 From: itozyun Date: Wed, 17 Jun 2015 13:23:03 +0900 Subject: [PATCH] rename files & fix X.EventDispatcher. --- 0.6.x/js/01_core/05_XArray.js | 0 0.6.x/js/01_core/{05_XString.js => 06_XString.js} | 0 0.6.x/js/01_core/{06_XURL.js => 08_XURL.js} | 0 0.6.x/js/01_core/{09_XPair.js => 10_XPair.js} | 0 .../js/01_core/{10_XCallback.js => 11_XClosure.js} | 102 +-------------------- 0.6.x/js/01_core/12_XCallback.js | 74 +++++++++++++++ 0.6.x/js/01_core/{11_XClass.js => 13_XClass.js} | 2 +- 0.6.x/js/01_core/{12_XEvent.js => 14_XEvent.js} | 0 ..._XEventDispatcher.js => 15_XEventDispatcher.js} | 51 +++++------ 0.6.x/js/01_core/{14_XTimer.js => 16_XTimer.js} | 0 0.6.x/js/01_core/{15_XSystem.js => 20_XSystem.js} | 0 .../01_core/{16_XViewPort.js => 21_XViewPort.js} | 0 0.6.x/js/01_core/{17_XLogger.js => 22_XLogger.js} | 0 0.6.x/js/02_dom/10_XNodeAnime.js | 2 +- 0.6.x/js/06_net/01_XNetXHR.js | 4 +- 0.6.x/js/06_net/05_XXHRGadget.js | 8 +- 0.6.x/js/06_net/10_XOAuth2.js | 69 +++++++------- 0.6.x/js/07_audio/01_XWebAudio.js | 38 ++++---- 0.6.x/js/import.js | 26 +++--- 19 files changed, 177 insertions(+), 199 deletions(-) create mode 100644 0.6.x/js/01_core/05_XArray.js rename 0.6.x/js/01_core/{05_XString.js => 06_XString.js} (100%) rename 0.6.x/js/01_core/{06_XURL.js => 08_XURL.js} (100%) rename 0.6.x/js/01_core/{09_XPair.js => 10_XPair.js} (100%) rename 0.6.x/js/01_core/{10_XCallback.js => 11_XClosure.js} (63%) create mode 100644 0.6.x/js/01_core/12_XCallback.js rename 0.6.x/js/01_core/{11_XClass.js => 13_XClass.js} (96%) rename 0.6.x/js/01_core/{12_XEvent.js => 14_XEvent.js} (100%) rename 0.6.x/js/01_core/{13_XEventDispatcher.js => 15_XEventDispatcher.js} (91%) rename 0.6.x/js/01_core/{14_XTimer.js => 16_XTimer.js} (100%) rename 0.6.x/js/01_core/{15_XSystem.js => 20_XSystem.js} (100%) rename 0.6.x/js/01_core/{16_XViewPort.js => 21_XViewPort.js} (100%) rename 0.6.x/js/01_core/{17_XLogger.js => 22_XLogger.js} (100%) diff --git a/0.6.x/js/01_core/05_XArray.js b/0.6.x/js/01_core/05_XArray.js new file mode 100644 index 0000000..e69de29 diff --git a/0.6.x/js/01_core/05_XString.js b/0.6.x/js/01_core/06_XString.js similarity index 100% rename from 0.6.x/js/01_core/05_XString.js rename to 0.6.x/js/01_core/06_XString.js diff --git a/0.6.x/js/01_core/06_XURL.js b/0.6.x/js/01_core/08_XURL.js similarity index 100% rename from 0.6.x/js/01_core/06_XURL.js rename to 0.6.x/js/01_core/08_XURL.js diff --git a/0.6.x/js/01_core/09_XPair.js b/0.6.x/js/01_core/10_XPair.js similarity index 100% rename from 0.6.x/js/01_core/09_XPair.js rename to 0.6.x/js/01_core/10_XPair.js diff --git a/0.6.x/js/01_core/10_XCallback.js b/0.6.x/js/01_core/11_XClosure.js similarity index 63% rename from 0.6.x/js/01_core/10_XCallback.js rename to 0.6.x/js/01_core/11_XClosure.js index 781a255..c9338f1 100644 --- a/0.6.x/js/01_core/10_XCallback.js +++ b/0.6.x/js/01_core/11_XClosure.js @@ -1,8 +1,3 @@ - -// ------------------------------------------------------------------------- // -// ------------ local variables -------------------------------------------- // -// ------------------------------------------------------------------------- // - var X_Callback_LIVE_LIST = [], @@ -19,33 +14,7 @@ var /** @const */ X_Callback_FUNC_ONLY = 3, /** @const */ - X_Callback_THIS_FUNCNAME = 4, - - /** @const */ - X_Callback_NONE = 0, - /** @const */ - X_Callback_UN_LISTEN = 1, - /** @const */ - X_Callback_STOP_PROPAGATION = 2, - /** @const */ - X_Callback_STOP_NOW = 4 | 2, // 同一階層のリスナーのキャンセル(上位へもキャンセル) - /** @const */ - X_Callback_PREVENT_DEFAULT = 8, // 結果動作のキャンセル, - /** @const */ - X_Callback_CAPTURE_POINTER = 16, - /** @const */ - X_Callback_RELEASE_POINTER = 32, - - /** @const */ - X_Callback_SYS_CANCEL = 64 | 4 | 2; - - - -/* - * handleEvent という関数のメンバーを持つオブジェクト - * @typedef {{ handleEvent : function }} - */ -var listener; + X_Callback_THIS_FUNCNAME = 4; /** *

クロージャに関するポリシーと再利用可能クロージャについて次の記事をご覧ください。 @@ -55,15 +24,6 @@ var listener; * X_Callback_create() で再利用可能なクロージャの作成。次のパターンで呼び出します。
* 最大で三つの引数を並べる一連のパターンは、 EventDispatcher.listen unlisten, listening や X.Timer.add, once でも使われますので、ここでよく目を通しておきます。 * - * - *
this コンテキスト+関数X_Callback_create( thisObject, func )func.call( thisObject ); - *
this コンテキスト+関数+追加引数X_Callback_create( thisObject, func, [ arg1, ...args ] )func.apply( thisObject, [ arg1, ...args ] ); - *
listener オブジェクトX_Callback_create( listener )listener.handleEvent(); コールバックに関数でなく handleEvent 関数をメンバに持つオブジェクトを渡すのは NN4 からある javascript のお約束です。 - *
listener オブジェクト+追加引数X_Callback_create( listener, [ arg1, ...args ] )listener.handleEvent.apply( listener, [ arg1, ...args ] ); - *
関数X_Callback_create( func )特別な操作は不要なので再利用可能クロージャは作られません。func をそのまま利用します。 - *
関数+引数X_Callback_create( func, [ arg1, ...args ] )func.apply( ?, [ arg1, ...args ] ); - *
- * *

再利用可能クロージャの破棄と再利用
* X_Callback_correct() によってクロージャは回収され再利用に備えます。
* 実は、クロージャが束縛するのは、this コンテキストやコールバック関数といった、そのものではなく、それらを一定のルールで格納したハッシュです。
@@ -94,7 +54,7 @@ var __CallbackHash__ = name : undefined, /** * コールバックの this コンテキスト。 - * @type {listener|object|undefined} + * @type {object|undefined} */ context : undefined, /** @@ -109,49 +69,6 @@ var __CallbackHash__ = proxy : X_Callback_proxyCallback }; -/** - * X.Timer と X.EventDispatcher からのコールバックの返り値を定義。 - * @namespace X.Callback - */ -X[ 'Callback' ] = { - /** - * このコールバックでは返り値による操作は無い。 - * @alias X.Callback.NONE - */ - 'NONE' : X_Callback_NONE, - /** - * X.Timer, X.EventDispatcher のコールバックでタイマーやイベントリスナの解除に使用。 - * @alias X.Callback.UN_LISTEN - */ - 'UN_LISTEN' : X_Callback_UN_LISTEN, - /** - * 上位階層へのイベント伝播のキャンセル。DOM イベントのコールバックの戻り値に指定すると e.stopPropagation() が呼ばれる。 - * @alias X.Callback.STOP_PROPAGATION - */ - 'STOP_PROPAGATION' : X_Callback_STOP_PROPAGATION, - /** - * 以降のイベントのディスパッチを中断する。STOP_PROPAGATION との違いは、次に控えているコールバックもキャンセルされる点。但し system によって追加されたイベントはキャンセルされない。 - * @alias X.Callback.STOP_NOW - */ - 'STOP_NOW' : X_Callback_STOP_NOW, - /** - * DOM イベントのコールバックの戻り値に指定すると e.preventDefault() が呼ばれる。 - * またフレームワーク内で定義されたデフォルト動作の回避にも使用される。 - * @alias X.Callback.PREVENT_DEFAULT - */ - 'PREVENT_DEFAULT' : X_Callback_PREVENT_DEFAULT, - /** - * X.UI の uinode でポインターイベントの戻り値に指定すると、以降のポインターベントを独占する。 - * @alias X.Callback.CAPTURE_POINTER - */ - 'CAPTURE_POINTER' : X_Callback_CAPTURE_POINTER, - /** - * X.UI の uinode でポインターイベントの戻り値に指定すると、以降のポインターベントを独占を解除する。 - * @alias X.Callback.RELEASE_POINTER - */ - 'RELEASE_POINTER' : X_Callback_RELEASE_POINTER -}; - // ------------------------------------------------------------------------- // // --- implements ---------------------------------------------------------- // // ------------------------------------------------------------------------- // @@ -269,8 +186,8 @@ function X_Callback_proxyCallback( xfunc, _args ){ funcName = funcName || 'handleEvent'; temp = thisObj[ funcName ]; if( X_Type_isFunction( temp ) ){ - return args.length === 0 ? thisObj[ 'handleEvent' ]() : - args.length === 1 ? thisObj[ 'handleEvent' ]( args[ 0 ] ) : temp.apply( thisObj, args ); + return args.length === 0 ? thisObj[ funcName ]() : + args.length === 1 ? thisObj[ funcName ]( args[ 0 ] ) : temp.apply( thisObj, args ); }; break; /* @@ -318,13 +235,4 @@ function X_Callback_monitor(){ }; function X_Callback_gc(){ X_Callback_POOL_LIST.length = 0; // ? -}; - -X_TEMP.onSystemReady.push( function( sys ){ - sys.monitor( X_Callback_monitor ); - sys.gc( X_Callback_gc ); -}); - - -console.log( 'X.Core.Callback' ); - +}; \ No newline at end of file diff --git a/0.6.x/js/01_core/12_XCallback.js b/0.6.x/js/01_core/12_XCallback.js new file mode 100644 index 0000000..a7d69fb --- /dev/null +++ b/0.6.x/js/01_core/12_XCallback.js @@ -0,0 +1,74 @@ + +// ------------------------------------------------------------------------- // +// ------------ local variables -------------------------------------------- // +// ------------------------------------------------------------------------- // + +var /** @const */ + X_Callback_NONE = 0, + /** @const */ + X_Callback_UN_LISTEN = 1, + /** @const */ + X_Callback_STOP_PROPAGATION = 2, + /** @const */ + X_Callback_STOP_NOW = 4 | 2, // 同一階層のリスナーのキャンセル(上位へもキャンセル) + /** @const */ + X_Callback_PREVENT_DEFAULT = 8, // 結果動作のキャンセル, + /** @const */ + X_Callback_CAPTURE_POINTER = 16, + /** @const */ + X_Callback_RELEASE_POINTER = 32, + + /** @const */ + X_Callback_SYS_CANCEL = 64 | 4 | 2; + +/** + * X.Timer と X.EventDispatcher からのコールバックの返り値を定義。 + * @namespace X.Callback + */ +X[ 'Callback' ] = { + /** + * このコールバックでは返り値による操作は無い。 + * @alias X.Callback.NONE + */ + 'NONE' : X_Callback_NONE, + /** + * X.Timer, X.EventDispatcher のコールバックでタイマーやイベントリスナの解除に使用。 + * @alias X.Callback.UN_LISTEN + */ + 'UN_LISTEN' : X_Callback_UN_LISTEN, + /** + * 上位階層へのイベント伝播のキャンセル。DOM イベントのコールバックの戻り値に指定すると e.stopPropagation() が呼ばれる。 + * @alias X.Callback.STOP_PROPAGATION + */ + 'STOP_PROPAGATION' : X_Callback_STOP_PROPAGATION, + /** + * 以降のイベントのディスパッチを中断する。STOP_PROPAGATION との違いは、次に控えているコールバックもキャンセルされる点。但し system によって追加されたイベントはキャンセルされない。 + * @alias X.Callback.STOP_NOW + */ + 'STOP_NOW' : X_Callback_STOP_NOW, + /** + * DOM イベントのコールバックの戻り値に指定すると e.preventDefault() が呼ばれる。 + * またフレームワーク内で定義されたデフォルト動作の回避にも使用される。 + * @alias X.Callback.PREVENT_DEFAULT + */ + 'PREVENT_DEFAULT' : X_Callback_PREVENT_DEFAULT, + /** + * X.UI の uinode でポインターイベントの戻り値に指定すると、以降のポインターベントを独占する。 + * @alias X.Callback.CAPTURE_POINTER + */ + 'CAPTURE_POINTER' : X_Callback_CAPTURE_POINTER, + /** + * X.UI の uinode でポインターイベントの戻り値に指定すると、以降のポインターベントを独占を解除する。 + * @alias X.Callback.RELEASE_POINTER + */ + 'RELEASE_POINTER' : X_Callback_RELEASE_POINTER +}; + +X_TEMP.onSystemReady.push( function( sys ){ + sys.monitor( X_Callback_monitor ); + sys.gc( X_Callback_gc ); +}); + + +console.log( 'X.Core.Callback' ); + diff --git a/0.6.x/js/01_core/11_XClass.js b/0.6.x/js/01_core/13_XClass.js similarity index 96% rename from 0.6.x/js/01_core/11_XClass.js rename to 0.6.x/js/01_core/13_XClass.js index e4b556a..ebe050b 100644 --- a/0.6.x/js/01_core/11_XClass.js +++ b/0.6.x/js/01_core/13_XClass.js @@ -25,7 +25,7 @@ var X_Class_traits = null, X_Class_useObjectCreate = false, // !!Object.create, http://jsperf.com/prototype-vs-object-create-perf X_Class_use_proto_ = !X_UA[ 'OperaMobile' ] && !X_UA[ 'OperaTablet' ] && !!X_emptyFunction.prototype.__proto__, - // Opera Mobile 12.10 Android11 IS01 でクラスのメンバが欠落する問題に遭遇。__proto__ を使わないと動作,,, + // Opera Mobile 12.10 Android11 IS01 でクラスのメンバが欠落する問題に遭遇。__proto__ を辞めると動作,,, X_Class_CommonMethods = /** @lends __ClassBase__.prototype */ diff --git a/0.6.x/js/01_core/12_XEvent.js b/0.6.x/js/01_core/14_XEvent.js similarity index 100% rename from 0.6.x/js/01_core/12_XEvent.js rename to 0.6.x/js/01_core/14_XEvent.js diff --git a/0.6.x/js/01_core/13_XEventDispatcher.js b/0.6.x/js/01_core/15_XEventDispatcher.js similarity index 91% rename from 0.6.x/js/01_core/13_XEventDispatcher.js rename to 0.6.x/js/01_core/15_XEventDispatcher.js index 27649db..4ee48a8 100644 --- a/0.6.x/js/01_core/13_XEventDispatcher.js +++ b/0.6.x/js/01_core/15_XEventDispatcher.js @@ -23,7 +23,6 @@ * * @class __Listeners__ * @private - * @abstract */ var X_Listeners_; @@ -39,7 +38,6 @@ var /** @const */ X_LISTENERS_KILL_RESERVED = 4; // X.Event で、イベントIDを 5 から始めているので注意。 - // ------------------------------------------------------------------------- // // ------------ local variables -------------------------------------------- // // ------------------------------------------------------------------------- // @@ -65,27 +63,15 @@ var X_EventDispatcher_once = false, // ------------------------------------------------------------------------- // /** + *

ぺったんR フレームワークの特徴であるイベントリスナの作法は次の記事で詳しく解説しています。 + * ぺったんRフレームワークのコールバックのお作法 + * *

    *
  1. as3 の EventDispatcher ライクなクラス。そのまま使ったり、継承したり。 *
  2. _rawObject メンバがいる場合、addEventListener, attachEvent, on 等で生のブラウザオブジェクトにリスナを登録する。 * window, document, HTMLElement, Image, XHR, Silverlight などが _rawObject になる。 *
  3. イベントディスパッチ中にリスナの追加が呼び出された場合、リスナはこれ以降のイベントから呼ばれます。同様にリスナの削除が呼ばれた場合、そのリスナが呼ばれることはありません。 *
- * - * - *

- * MDN > 開発者向けのWeb技術 > Web API インターフェイス > EventTarget > EventTarget.addEventListener イベント発送中のリスナーの追加 - *

EventListener がイベント処理中に EventTarget に追加された場合、それが現在のアクションによって実行されることはありませんが、浮上フェーズのように、後の段階のイベントフローで実行されるかもしれません。 - * - * - * - *

- * MDN > 開発者向けのWeb技術 > Web API インターフェイス > EventTarget > EventTarget.removeEventListener 注記 - *

イベントリスナーが イベントを処理中であるイベントターゲットから削除された場合、現在のアクションによってそのイベントリスナーが実行されることはありません。 - *

イベントリスナーは、決して削除された後に実行されることはありません。 - *

イベントターゲット上にある現在のどのイベントリスナーも指定していない引数付きの removeEventListener は、何の効果もありません。 - * - * *

listen, unlisten, dispatch という addEventListener, removeEventListener, dispatchEvent に対応する関数を持ちます。 * また listening という ActionScript3 の hasEventListener に相当する関数を持ちます。 * @@ -123,7 +109,7 @@ var X_EventDispatcher = X[ 'EventDispatcher' ] = * Arrayには、{kind:種類,context:コンテキスト(thisObject),func:コールバック関数,supplement:サプリメントする引数の配列} というハッシュ、または関数が蓄えられています。 * * @private - * @type {__X_EventDispatcher_Listeners__} + * @type {__Listeners__} */ '_listeners' : null, @@ -205,12 +191,12 @@ var X_EventDispatcher = X[ 'EventDispatcher' ] = if( ( unlistens = listeners[ X_LISTENERS_UNLISTENS ] ) && ( unlistens = unlistens[ opt_type ] ) ){ for( i = unlistens.length; i; ){ f = unlistens[ --i ]; - if( f === cbHash || ( f.context === cbHash.context && f.func === cbHash.func && f.supplement === cbHash.supplement && f.lock === lock ) ) return false; + if( f === cbHash || ( f.context === cbHash.context && f.func === cbHash.func && f.name === cbHash.name && f.supplement === cbHash.supplement && f.lock === lock ) ) return false; }; }; for( i = list.length; i; ){ f = list[ --i ]; - if( f === cbHash || ( f.context === cbHash.context && f.func === cbHash.func && f.supplement === cbHash.supplement && f.lock === lock ) ){ + if( f === cbHash || ( f.context === cbHash.context && f.func === cbHash.func && f.name === cbHash.name && f.supplement === cbHash.supplement && f.lock === lock ) ){ // index を要求された場合、lock されていない、または unlock なら index を返す return X_EventDispatcher_needsIndex ? i : true; }; @@ -412,7 +398,7 @@ function X_EventDispatcher_listen( type, opt_arg1, opt_arg2, opt_arg3 ){ if( !listeners ) listeners = this[ '_listeners' ] = {}; list = listeners[ type ] || ( listeners[ type ] = [] ); - add && X_EventDispatcher_addEvent( this, type, raw, list ); + add && X_EventDispatcher_actualAddEvent( this, type, raw, list ); f = X_Callback_classifyCallbackArgs( opt_arg1, opt_arg2, opt_arg3, this ); list[ list.length ] = f; @@ -480,11 +466,13 @@ function X_EventDispatcher_unlisten( opt_type, opt_arg1, opt_arg2, opt_arg3 ){ ( listeners[ X_LISTENERS_UNLISTENS ][ opt_type ] = [ f ] ); } else { delete f.once; - list.splice( i, 1 ); - if( !list.length ){ - raw = this[ '_rawObject' ] || X_UA_DOM.IE4 && X_Node__ie4getRawNode( this ); + if( list.length !== 1 ){ + list.splice( i, 1 ); + } else { + list.length = 0; + delete listeners[ opt_type ]; - //empty = X_Object_isEmpty( listeners ); + // TODO カウンター empty = true; for( k in listeners ){ @@ -492,9 +480,12 @@ function X_EventDispatcher_unlisten( opt_type, opt_arg1, opt_arg2, opt_arg3 ){ empty = false; break; }; - if( raw && !X_String_isNumberString( '' + opt_type ) ){ // 数字イベントの除外 - X_EventDispatcher_removeEvent( this, opt_type, raw, list, !empty ); + + if( !X_String_isNumberString( '' + opt_type ) ){ // 数字イベントの除外 + raw = this[ '_rawObject' ] || X_UA_DOM.IE4 && X_Node__ie4getRawNode( this ); + raw && X_EventDispatcher_actualRemoveEvent( this, opt_type, raw, list, !empty ); }; + if( empty ) delete this[ '_listeners' ]; }; }; @@ -525,7 +516,7 @@ function X_EventDispatcher_unlistenAll( that ){ }; }; -function X_EventDispatcher_addEvent( that, type, raw, list ){ +function X_EventDispatcher_actualAddEvent( that, type, raw, list ){ var i, f; X_EventDispatcher_lock || ( type = X_Event_Rename[ type ] || type ); @@ -638,7 +629,7 @@ function X_EventDispatcher_sliverLightDispatch( sender, e, type ){ return this[ 'dispatch' ]( type ); }; -function X_EventDispatcher_removeEvent( that, type, raw, list, skip ){ +function X_EventDispatcher_actualRemoveEvent( that, type, raw, list, skip ){ var i; X_EventDispatcher_unlock || ( type = X_Event_Rename[ type ] || type ); @@ -814,7 +805,7 @@ if( X_UA[ 'WebKit' ] < 525.13 ){ // Safari3- function X_EventDispatcher_toggleAllEvents( that, add ){ var list = that[ '_listeners' ], raw = that[ '_rawObject' ] || X_UA_DOM.IE4 && X_Node__ie4getRawNode( that ), - func = add ? X_EventDispatcher_addEvent : X_EventDispatcher_removeEvent, + func = add ? X_EventDispatcher_actualAddEvent : X_EventDispatcher_actualRemoveEvent, type; if( !list || !raw ) return; for( type in list ){ diff --git a/0.6.x/js/01_core/14_XTimer.js b/0.6.x/js/01_core/16_XTimer.js similarity index 100% rename from 0.6.x/js/01_core/14_XTimer.js rename to 0.6.x/js/01_core/16_XTimer.js diff --git a/0.6.x/js/01_core/15_XSystem.js b/0.6.x/js/01_core/20_XSystem.js similarity index 100% rename from 0.6.x/js/01_core/15_XSystem.js rename to 0.6.x/js/01_core/20_XSystem.js diff --git a/0.6.x/js/01_core/16_XViewPort.js b/0.6.x/js/01_core/21_XViewPort.js similarity index 100% rename from 0.6.x/js/01_core/16_XViewPort.js rename to 0.6.x/js/01_core/21_XViewPort.js diff --git a/0.6.x/js/01_core/17_XLogger.js b/0.6.x/js/01_core/22_XLogger.js similarity index 100% rename from 0.6.x/js/01_core/17_XLogger.js rename to 0.6.x/js/01_core/22_XLogger.js diff --git a/0.6.x/js/02_dom/10_XNodeAnime.js b/0.6.x/js/02_dom/10_XNodeAnime.js index c83aef5..04709bf 100644 --- a/0.6.x/js/02_dom/10_XNodeAnime.js +++ b/0.6.x/js/02_dom/10_XNodeAnime.js @@ -236,7 +236,7 @@ function X_Node_Anime_updateAnimations( v, updateNow ){ function X_Node_Anime_detectAnimationLayers(){ var i = X_Node_ANIMATIONS.length, l = i, - j, xnode, parent, hasGPUChild, remove; + j, xnode, parent, _xnode, hasGPUChild, remove; for( ; i; ){ xnode = X_Node_ANIMATIONS[ --i ]; diff --git a/0.6.x/js/06_net/01_XNetXHR.js b/0.6.x/js/06_net/01_XNetXHR.js index 1f49f10..f6b8357 100644 --- a/0.6.x/js/06_net/01_XNetXHR.js +++ b/0.6.x/js/06_net/01_XNetXHR.js @@ -155,7 +155,7 @@ X_TEMP.X_Net_XHR_params = { xDomain = !X_URL_isSameDomain( url ), isFile = X_URL_isLocal( url ), init, - tmp; + tmp, p; this._dataType = obj[ 'dataType' ]; @@ -526,7 +526,7 @@ X_TEMP.X_Net_XHR_params = { */ function X_NET_XHR_parseResponseHeaders( headerStr ){ - var headers = {}, headerPairs, i = 0, l, headerPair, index, key, value; + var headers = {}, headerPairs, i = 0, l, headerPair, index, key, val; if( !headerStr ) return headers; diff --git a/0.6.x/js/06_net/05_XXHRGadget.js b/0.6.x/js/06_net/05_XXHRGadget.js index 0a4cebc..8e8386c 100644 --- a/0.6.x/js/06_net/05_XXHRGadget.js +++ b/0.6.x/js/06_net/05_XXHRGadget.js @@ -176,7 +176,13 @@ X_TEMP.X_Net_GIMR_props = { name : X_NET_GIMR_iframeName, id : X_NET_GIMR_iframeName, src : X_NET_GIMR_GADGET_URL + '#' + encodeURIComponent( - X_JSON_stringify( { 'img' : X_URL_toAbsolutePath( X_NET_GIMR_IMAGE_URL ), 'len' : 1000, 'itvl' : 200 } ) ), + X_JSON_stringify( { + 'img' : X_URL_toAbsolutePath( X_NET_GIMR_IMAGE_URL ), + // https://code.google.com/p/xssinterface/source/browse/trunk/js/xssinterface.js + 'len' : X_UA[ 'IE' ] ? 2000 : 6000, + 'itvl' : 333 + } ) + ), scrolling : 'no', allowtransparency : 'no', frameborder : 0, diff --git a/0.6.x/js/06_net/10_XOAuth2.js b/0.6.x/js/06_net/10_XOAuth2.js index 3564a13..a3967ff 100644 --- a/0.6.x/js/06_net/10_XOAuth2.js +++ b/0.6.x/js/06_net/10_XOAuth2.js @@ -29,6 +29,7 @@ oauth2 = X.OAuth2({ 'tokenEndpoint' : 'https://accounts.google.com/o/oauth2/token', 'redirectURI' : X.URL.cleanup( document.location.href ), // 専用の軽量ページを用意してもよいが、現在のアドレスでも可能 'scopes' : [ 'https://www.googleapis.com/auth/blogger' ], + 'refreshMargin' : 300000, 'authorizeWindowWidth' : 500, 'authorizeWindowHeight' : 500 }).listen( [ X.Event.NEED_AUTH, X.Event.CANCELED, X.Event.SUCCESS, X.Event.ERROR, X.Event.PROGRESS ], updateOAuth2State ); @@ -58,7 +59,7 @@ X[ 'OAuth2' ] = X_EventDispatcher[ 'inherits' ]( obj.onAuthError = X_NET_OAUTH2_onXHR401Error; obj.updateRequest = X_NET_OAUTH2_updateRequest; - if( _getAccessToken( this ) && ( expires_at = _getAccessTokenExpiry( this ) ) ){ + if( X_OAuth2_getAccessToken( this ) && ( expires_at = X_OAuth2_getAccessTokenExpiry( this ) ) ){ if( expires_at < X_Timer_now() + ( obj[ 'refreshMargin' ] || 300000 ) ){ // 寿命が5分を切った this[ 'refreshToken' ](); } else { @@ -174,7 +175,7 @@ X[ 'OAuth2' ] = X_EventDispatcher[ 'inherits' ]( 'client_id' : pair[ 'clientID' ], 'client_secret' : pair[ 'clientSecret' ], 'grant_type' : 'refresh_token', - 'refresh_token' : _getRefreshToken( this ) + 'refresh_token' : X_OAuth2_getRefreshToken( this ) }), 'dataType' : 'json', 'headers' : { @@ -203,9 +204,9 @@ function X_NET_OAUTH2_handleEvent( e ){ case X_EVENT_SUCCESS : pair.refreshTimerID && X_Timer_remove( pair.refreshTimerID ); - if( _getRefreshToken( this ) ){ + if( X_OAuth2_getRefreshToken( this ) ){ // 自動リフレッシュ - pair.refreshTimerID = X_Timer_once( _getAccessTokenExpiry( this ) - X_Timer_now() - pair[ 'refreshMargin' ], this, this[ 'refreshToken' ] ); + pair.refreshTimerID = X_Timer_once( X_OAuth2_getAccessTokenExpiry( this ) - X_Timer_now() - pair[ 'refreshMargin' ], this, this[ 'refreshToken' ] ); }; }; }; @@ -269,7 +270,7 @@ function X_Net_OAuth2_responceHandler( e ){ switch( e.type ){ case X_EVENT_SUCCESS : if( isRefresh && data.error ){ - _removeRefreshToken( this ); + X_OAuth2_removeRefreshToken( this ); pair.oauth2State = 0; this[ 'asyncDispatch' ]( { type : X_EVENT_ERROR, message : 'Refresh access token error.' } ); this[ 'asyncDispatch' ]( X_EVENT_NEED_AUTH ); @@ -282,14 +283,14 @@ function X_Net_OAuth2_responceHandler( e ){ return; }; - _setAccessToken( this, data[ 'access_token' ] || '' ); - _setRefreshToken( this, data[ 'refresh_token' ] || '' ); + X_OAuth2_setAccessToken( this, data[ 'access_token' ] || '' ); + X_OAuth2_setRefreshToken( this, data[ 'refresh_token' ] || '' ); if( data[ 'expires_in' ] ){ - _setAccessTokenExpiry( this, X_Timer_now() + data[ 'expires_in' ] * 1000 ); + X_OAuth2_setAccessTokenExpiry( this, X_Timer_now() + data[ 'expires_in' ] * 1000 ); } else - if( _getAccessTokenExpiry( this ) ){ - _removeAccessTokenExpiry( this ); + if( X_OAuth2_getAccessTokenExpiry( this ) ){ + X_OAuth2_removeAccessTokenExpiry( this ); }; pair.oauth2State = 4; @@ -301,15 +302,15 @@ function X_Net_OAuth2_responceHandler( e ){ // other error, not auth pair.oauth2State = 0; this[ 'asyncDispatch' ]( { type : X_EVENT_ERROR, message : 'Refresh access token error.' } ); - _removeRefreshToken( this ); + X_OAuth2_removeRefreshToken( this ); this[ 'asyncDispatch' ]( X_EVENT_NEED_AUTH ); } else - if( _getAuthMechanism( this ) === 'param' ){ + if( X_OAuth2_getAuthMechanism( this ) === 'param' ){ pair.oauth2State = 0; this[ 'asyncDispatch' ]( { type : X_EVENT_ERROR, message : 'network-error' } ); } else { pair.oauth2State = 0; - _setAuthMechanism( this, 'param' ); + X_OAuth2_setAuthMechanism( this, 'param' ); this[ 'asyncDispatch' ]( { type : X_EVENT_PROGRESS, message : 'Refresh access token failed. retry header -> param. ' } ); // retry X_Net_OAuth2_authorizationCode( this, pair ); @@ -323,7 +324,7 @@ function X_NET_OAUTH2_onXHR401Error( oauth2, e ){ headers = e[ 'headers' ], xhr, bearerParams, headersExposed = false; - if( _getAuthMechanism( oauth2 ) !== 'param' ){ + if( X_OAuth2_getAuthMechanism( oauth2 ) !== 'param' ){ xhr = X_NET_currentWrapper[ '_rawObject' ]; headersExposed = !X_Net_XHR_createXDR || !!headers; // this is a hack for Firefox and IE bearerParams = headersExposed && ( headers[ 'WWW-Authenticate' ] || headers[ 'www-authenticate' ] ); @@ -335,21 +336,21 @@ function X_NET_OAUTH2_onXHR401Error( oauth2, e ){ pair.oauth2State = 0; oauth2[ 'asyncDispatch' ]( X_EVENT_NEED_AUTH ); } else - if ((( bearerParams && bearerParams.indexOf( 'invalid_token' ) !== -1 ) || !headersExposed) && _getRefreshToken( oauth2 ) ) { - _removeAccessToken( oauth2 ); // It doesn't work any more. + if ((( bearerParams && bearerParams.indexOf( 'invalid_token' ) !== -1 ) || !headersExposed) && X_OAuth2_getRefreshToken( oauth2 ) ) { + X_OAuth2_removeAccessToken( oauth2 ); // It doesn't work any more. pair.oauth2State = 3; oauth2[ 'refreshToken' ](); } else { - //if (!headersExposed && !_getRefreshToken( oauth2 )) { - _removeAccessToken( oauth2 ); // It doesn't work any more. + //if (!headersExposed && !X_OAuth2_getRefreshToken( oauth2 )) { + X_OAuth2_removeAccessToken( oauth2 ); // It doesn't work any more. pair.oauth2State = 0; oauth2[ 'asyncDispatch' ]( X_EVENT_NEED_AUTH ); }; }; function X_NET_OAUTH2_updateRequest( oauth2, request ){ - var token = _getAccessToken( oauth2 ), - mechanism = _getAuthMechanism( oauth2 ), + var token = X_OAuth2_getAccessToken( oauth2 ), + mechanism = X_OAuth2_getAuthMechanism( oauth2 ), url = request[ 'url' ], headers; @@ -363,25 +364,25 @@ function X_NET_OAUTH2_updateRequest( oauth2, request ){ }; }; -function _getAccessToken( that ){ return updateLocalStorage( '', that, 'accessToken' ); } -function _getRefreshToken( that){ return updateLocalStorage( '', that, 'refreshToken' ); } -function _getAccessTokenExpiry( that ){ return parseInt( updateLocalStorage( '', that, 'tokenExpiry' ) ) || 0; } -function _getAuthMechanism( that ){ +function X_OAuth2_getAccessToken( that ){ return X_OAuth2_updateLocalStorage( '', that, 'accessToken' ); } +function X_OAuth2_getRefreshToken( that){ return X_OAuth2_updateLocalStorage( '', that, 'refreshToken' ); } +function X_OAuth2_getAccessTokenExpiry( that ){ return parseInt( X_OAuth2_updateLocalStorage( '', that, 'tokenExpiry' ) ) || 0; } +function X_OAuth2_getAuthMechanism( that ){ // TODO use gadget | flash ... // IE's XDomainRequest doesn't support sending headers, so don't try. - return X_Net_XHR_createXDR ? 'param' : updateLocalStorage( '', that, 'AuthMechanism' ); + return X_Net_XHR_createXDR ? 'param' : X_OAuth2_updateLocalStorage( '', that, 'AuthMechanism' ); } -function _setAccessToken( that, value ){ updateLocalStorage( '+', that, 'accessToken' , value); } -function _setRefreshToken( that, value ){ updateLocalStorage( '+', that, 'refreshToken', value); } -function _setAccessTokenExpiry( that, value ){ updateLocalStorage( '+', that, 'tokenExpiry', value); } -function _setAuthMechanism( that, value ){ updateLocalStorage( '+', that, 'AuthMechanism', value); } +function X_OAuth2_setAccessToken( that, value ){ X_OAuth2_updateLocalStorage( '+', that, 'accessToken' , value); } +function X_OAuth2_setRefreshToken( that, value ){ X_OAuth2_updateLocalStorage( '+', that, 'refreshToken', value); } +function X_OAuth2_setAccessTokenExpiry( that, value ){ X_OAuth2_updateLocalStorage( '+', that, 'tokenExpiry', value); } +function X_OAuth2_setAuthMechanism( that, value ){ X_OAuth2_updateLocalStorage( '+', that, 'AuthMechanism', value); } -function _removeAccessToken( that ){ updateLocalStorage( '-', that, 'accessToken' ); } -function _removeRefreshToken( that ){ updateLocalStorage( '-', that, 'refreshToken' ); } -function _removeAccessTokenExpiry( that ){ updateLocalStorage( '-', that, 'tokenExpiry' ); } -function _removeAuthMechanism( that ){ updateLocalStorage( '-', that, 'AuthMechanism' ); } +function X_OAuth2_removeAccessToken( that ){ X_OAuth2_updateLocalStorage( '-', that, 'accessToken' ); } +function X_OAuth2_removeRefreshToken( that ){ X_OAuth2_updateLocalStorage( '-', that, 'refreshToken' ); } +function X_OAuth2_removeAccessTokenExpiry( that ){ X_OAuth2_updateLocalStorage( '-', that, 'tokenExpiry' ); } +function X_OAuth2_removeAuthMechanism( that ){ X_OAuth2_updateLocalStorage( '-', that, 'AuthMechanism' ); } -function updateLocalStorage( cmd, that, name, value ){ +function X_OAuth2_updateLocalStorage( cmd, that, name, value ){ var action = cmd === '+' ? 'setItem' : cmd === '-' ? 'removeItem' : 'getItem', pair; diff --git a/0.6.x/js/07_audio/01_XWebAudio.js b/0.6.x/js/07_audio/01_XWebAudio.js index 66571d1..56fdc2e 100644 --- a/0.6.x/js/07_audio/01_XWebAudio.js +++ b/0.6.x/js/07_audio/01_XWebAudio.js @@ -3,7 +3,8 @@ var X_Audio_WebAudio_context = !X_UA[ 'iPhone_4s' ] && !X_UA[ 'iPad_2Mini1' ] !( X_UA[ 'Gecko' ] && X_UA[ 'Android' ] ) && ( window.AudioContext || window.webkitAudioContext ), X_Audio_BUFFER_LIST = [], - X_Audio_WebAudioWrapper; + X_Audio_WebAudioWrapper, + X_Audio_BufferLoader; /* * iPhone 4s 以下、iPad2以下、iPad mini 1以下, iPod touch 4G 以下は不可 @@ -155,7 +156,7 @@ if( X_Audio_WebAudio_context ){ this.setState( option ); - this[ 'listenOnce' ]( X_EVENT_KILL_INSTANCE, X_WebAudio_handleEvent ); + this[ 'listenOnce' ]( X_EVENT_KILL_INSTANCE, this.onKill ); if( loader.buffer || loader.error ){ this._onLoadBufferComplete(); @@ -163,6 +164,20 @@ if( X_Audio_WebAudio_context ){ loader[ 'listenOnce' ]( X_EVENT_COMPLETE, this, this._onLoadBufferComplete ); }; }, + + onKill : function(){ + this.loader[ 'unlisten' ]( X_EVENT_COMPLETE, this, this._onLoadBufferComplete ) + .unregister( this ); + + delete this.buffer; + + this.playing && this.actualPause(); + this.source && this._sourceDispose(); + + this._onended && X_Callback_correct( this._onended ); + + this.gainNode && this.gainNode.disconnect(); + }, _onLoadBufferComplete : function( e ){ var loader = this.loader, buffer = loader.buffer; @@ -320,25 +335,6 @@ if( X_Audio_WebAudio_context ){ } ); - function X_WebAudio_handleEvent( e ){ - switch( e.type ){ - - case X_EVENT_KILL_INSTANCE : - this.loader[ 'unlisten' ]( X_EVENT_COMPLETE, this, this._onLoadBufferComplete ) - .unregister( this ); - - delete this.buffer; - - this.playing && this.actualPause(); - this.source && this._sourceDispose(); - - this._onended && X_Callback_correct( this._onended ); - - this.gainNode && this.gainNode.disconnect(); - break; - }; - }; - /* * http://qiita.com/sou/items/5688d4e7d3a37b4e2ff1 * L-01F 等の一部端末で Web Audio API の再生結果に特定条件下でノイズが混ざることがある。 diff --git a/0.6.x/js/import.js b/0.6.x/js/import.js index c26df4c..11ebfcb 100644 --- a/0.6.x/js/import.js +++ b/0.6.x/js/import.js @@ -12,19 +12,21 @@ document.write( [ 'js/01_core/03_XType.js', 'js/01_core/04_XObject.js', - 'js/01_core/05_XString.js', - 'js/01_core/06_XURL.js', - - 'js/01_core/09_XPair.js', - 'js/01_core/10_XCallback.js', - 'js/01_core/11_XClass.js', - 'js/01_core/12_XEvent.js', - 'js/01_core/13_XEventDispatcher.js', - 'js/01_core/14_XTimer.js', + 'js/01_core/05_XArray.js', + 'js/01_core/06_XString.js', + 'js/01_core/08_XURL.js', + + 'js/01_core/10_XPair.js', + 'js/01_core/11_XClosure.js', + 'js/01_core/12_XCallback.js', + 'js/01_core/13_XClass.js', + 'js/01_core/14_XEvent.js', + 'js/01_core/15_XEventDispatcher.js', + 'js/01_core/16_XTimer.js', - 'js/01_core/15_XSystem.js', - 'js/01_core/16_XViewPort.js', - 'js/01_core/17_XLogger.js', + 'js/01_core/20_XSystem.js', + 'js/01_core/21_XViewPort.js', + 'js/01_core/22_XLogger.js', 'js/02_dom/00_XDoc.js', -- 2.11.0