From: itozyun Date: Wed, 25 Nov 2015 05:48:45 +0000 (+0900) Subject: Version 0.6.197, add X.Util.Windfow. X-Git-Url: http://git.osdn.jp/view?p=pettanr%2FclientJs.git;a=commitdiff_plain;h=5633b955bc9fcd998e8ecf7e8e30c311aafc588c Version 0.6.197, add X.Util.Windfow. --- diff --git a/0.6.x/js/02_dom/04_XBoxModel.js b/0.6.x/js/02_dom/04_XBoxModel.js index 43d7e99..d96d253 100644 --- a/0.6.x/js/02_dom/04_XBoxModel.js +++ b/0.6.x/js/02_dom/04_XBoxModel.js @@ -213,12 +213,12 @@ function X_Node_y(){ }; /** - * 要素の文書内の位置。引数に xnode を与えた場合、 + * 要素の文書内の位置。 * @alias Node.prototype.offset * @return {object} { x: {number}, y : {number} } * @example node.offset(); */ -function X_Node_offset( xnode ){ +function X_Node_offset(){ var flags = this[ '_flags' ], offset = { x : 0, y : 0 }, obj, parent, elm; diff --git a/0.6.x/js/05_util/01_XNinjaIframe.js b/0.6.x/js/05_util/01_XNinjaIframe.js index 702706d..3bd2e4c 100644 --- a/0.6.x/js/05_util/01_XNinjaIframe.js +++ b/0.6.x/js/05_util/01_XNinjaIframe.js @@ -7,21 +7,40 @@ * * @alias X.Util.NinjaIframe * @class NinjaIframe 隠し iframe 機能を提供します。 - * @constructs NinjaIframe * @extends {Node} */ var X_NinjaIframe = X[ 'Util' ][ 'NinjaIframe' ] = Node[ 'inherits' ]( 'NinjaIframe', + + /** @lends NinjaIframe.prototype */ { - autoRefresh : 0, + /* autoRefresh : 0, */ + /** + * iframe の contentWindow + * @private + * @type {window} */ _iwin : null, + /** + * iframe に write する html 文字時列 + * @type {string} */ _contentHTML : '', + + /** + * iframe の name + * @private + * @type {string} */ _name : '', + + /** + * iframe への html 文字列の write が完了した + * @private + * @type {string} */ _ready : false, 'Constructor' : function( html ){ + // TODO src も設定可能に this._name = 'hidden-iframe-' + X_Timer_now(); // https://github.com/polygonplanet/Pot.js/blob/master/src/Worker.js @@ -59,6 +78,11 @@ var X_NinjaIframe = X[ 'Util' ][ 'NinjaIframe' ] = Node[ 'inherits' ]( X_ViewPort[ 'listenOnce' ]( X_EVENT_AFTER_UPDATE, this, X_Util_NinjaIframe_handleEvent ); }, + /** + * iframe 内をリフレッシュ、または内容を上書きする + * @param {string=} opt_contentHTML html文字列 + * @return {NinjaIframe} チェーンメソッド + */ 'refresh' : function( opt_contentHTML ){ var raw = this[ '_rawObject' ], idoc; @@ -82,7 +106,6 @@ var X_NinjaIframe = X[ 'Util' ][ 'NinjaIframe' ] = Node[ 'inherits' ]( if( !( X_UA[ 'IE' ] < 9 ) ){ X_Util_NinjaIframe_writeToIframe( this ); - //this._ready = true; }; return this; @@ -106,7 +129,6 @@ function X_Util_NinjaIframe_handleEvent( e ){ if( !( X_UA[ 'IE' ] < 9 ) ){ X_Util_NinjaIframe_writeToIframe( this ); - //this._ready = true; return; }; //break; これあると IE8 で駄目! @@ -116,7 +138,6 @@ function X_Util_NinjaIframe_handleEvent( e ){ // ie9- if( !this._ready ){ X_Util_NinjaIframe_writeToIframe( this ); - //this._ready = true; break; }; // onload @@ -143,7 +164,7 @@ function X_Util_NinjaIframe_writeToIframe( that ){ idoc = raw.contentDocument || that._iwin.document, html = that._contentHTML; - that._ready = true; // これを削除すると ie6,7,8 で Stack overflow at line : 0 意味不明 + that._ready = true; // これを削除すると ie6,7,8 で Stack overflow at line : 0 意味不明 'readystatechange' が繰り返し起こりループする?? delete that._contentHTML; idoc.open(); diff --git a/0.6.x/js/05_util/06_XWindow.js b/0.6.x/js/05_util/06_XWindow.js new file mode 100644 index 0000000..f3941ee --- /dev/null +++ b/0.6.x/js/05_util/06_XWindow.js @@ -0,0 +1,121 @@ +/** + * 別窓(別タブ)の操作 + *
    + *
  1. win.kill() で別窓を閉じる + *
  2. win.kill() 以外で閉じられた場合、ユーザーの[x]ボタン操作や、他のscriptによって閉じられた場合、X.Event.UNLOAD イベントを発して自身を kill する。 + *
+ * イベント + *
+ *
X.Event.UNLOAD
win.kill() 以外で閉じられた場合に通知、自身はkillする + *
X.Event.ERROR
他ドメインに遷移した等の理由で win.write() による書き換えに失敗した場合 + *
+ * + * @example // 別ページの表示 + * win = X.Util.Window( { url : 'other.html' } ); + * // コンテンツの書き込み + * win = X.Util.Window( { html : '<p>Hello,world!</p>' } ); + * // 閉じる + * win.kill(); + * + * @alias X.Util.Window + * @class Window 別窓(別タブ) + * @extends {EventDispatcher} + */ +var X_Window = X[ 'Util' ][ 'Window' ] = X_EventDispatcher[ 'inherits' ]( + 'X.Window', + + /** @lends X.Util.Window.prototype */ + { + + // TODO pair 側に + /** + * closed の監視用タイマーID + * @private + * @type {number} */ + _timerID : 0, + + 'Constructor' : function( options ){ + var url = options[ 'url' ], + page = window.open( url || ''/* 'about:blank' */, options[ 'name' ] || '', options[ 'params' ] || '' ), + html = options[ 'html' ], + doc = X_Script_try( X_Object_find, [ page, 'document' ] ); + + X_Pair_create( this, page ); + + if( !url && html ){ + this[ 'write' ]( html ); + }; + + X_ViewPort[ 'listenOnce' ]( X_EVENT_UNLOAD, this, X_Util_Window_handleEvent ); + this[ 'listenOnce' ]( [ X_EVENT_UNLOAD, X_EVENT_KILL_INSTANCE ], X_Util_Window_handleEvent ); + + this._timerID = X_Timer_add( options[ 'interval' ] || 500, 0, this, X_Util_Window_onTimer ); + }, + + /** + * 別窓が閉じられたか? + *
    + *
  1. ユーザーの[x]クリック操作等 + *
  2. 別窓内の script, または他の script + *
+ * @return {boolean} + */ + 'closed' : function(){ + return X_Script_try( X_Object_find, [ X_Pair_get( this ), 'closed' ] ); + }, + + /** + * 別窓の内容を書き換える + * @param {string=} opt_html html文字列 + * @return {Window} チェーンメソッド + */ + 'write' : function( opt_html ){ + var doc = X_Script_try( X_Object_find, [ X_Pair_get( this ), 'document' ] ); + + if( doc ){ + doc.open(); + doc.write( opt_html || '' ); // TODO 無毒化 + doc.close(); + } else { + this[ 'asyncDispatch' ]( X_EVENT_ERROR ); + }; + + return this; + } + + // TODO url + + } +); + +function X_Util_Window_onTimer( e ){ + if( this[ 'closed' ]() ){ + this[ 'asyncDispatch' ]( X_EVENT_UNLOAD ); + delete this._timerID; + return X_CALLBACK_UN_LISTEN; + }; +}; + +function X_Util_Window_handleEvent( e ){ + var page = X_Pair_get( this ); + + switch( e.type ){ + case X_EVENT_UNLOAD : + this[ 'kill' ](); + break; + + case X_EVENT_KILL_INSTANCE : + if( page && !this[ 'closed' ]() ){ + if( 9 < X_UA[ 'IEHost' ] ){ + page.close(); + } else { + page.open( 'about:blank', '_self' ).close(); + }; + X_Pair_release( this, page ); + }; + this._timerID && X_Timer_remove( this._timerID ); + X_ViewPort[ 'unlisten' ]( X_EVENT_UNLOAD, this, X_Util_Window_handleEvent ); + break; + }; +}; + diff --git a/0.6.x/js/06_net/10_XOAuth2.js b/0.6.x/js/06_net/10_XOAuth2.js index b881ec2..961d0a2 100644 --- a/0.6.x/js/06_net/10_XOAuth2.js +++ b/0.6.x/js/06_net/10_XOAuth2.js @@ -114,7 +114,7 @@ X[ 'OAuth2' ] = X_EventDispatcher[ 'inherits' ]( 'response_type' : 'code', 'client_id' : pair[ 'clientID' ], 'redirect_uri' : pair[ 'redirectURI' ], - 'scope' : ( pair[ 'scopes' ] || [] ).join(' ') + 'scope' : ( pair[ 'scopes' ] || [] ).join( ' ' ) } ), 'oauthauthorize',