X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F05_util%2F01_XNinjaIframe.js;h=c0a77d1d435eff5f2789e7269df347a529e42433;hb=ef25747bebf1799d49f9bd0d64e339da9ea61d13;hp=9964d5859b150062003659e923d4bce8a065a97c;hpb=3d352d8bf476ab57cc333e8d02d0e6ea5efa69b7;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/05_util/01_XNinjaIframe.js b/0.6.x/js/05_util/01_XNinjaIframe.js index 9964d58..c0a77d1 100644 --- a/0.6.x/js/05_util/01_XNinjaIframe.js +++ b/0.6.x/js/05_util/01_XNinjaIframe.js @@ -6,29 +6,45 @@ * モバイルブラウザでの iframe の挙動(Mobile Safari, Chrome for Android) * * @alias X.Util.NinjaIframe - * @class 隠し iframe 機能を提供します。 - * @constructor - * @constructs NinjaIframe + * @class NinjaIframe 隠し iframe 機能を提供します。 * @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 - X_Node_newByTag = true; - this[ 'Super' ]( 'IFRAME', { @@ -54,12 +70,17 @@ var X_NinjaIframe = X[ 'Util' ][ 'NinjaIframe' ] = Node[ 'inherits' ]( if( html ) this._contentHTML = html; - this[ 'appendTo' ]( X_Node_body /* X_Node_systemNode */ ) + this[ 'appendTo' ]( X_Node_systemNode ) [ 'listenOnce' ]( X_EVENT_KILL_INSTANCE, X_Util_NinjaIframe_handleEvent ); 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; @@ -77,13 +98,12 @@ var X_NinjaIframe = X[ 'Util' ][ 'NinjaIframe' ] = Node[ 'inherits' ]( this._iwin.location.reload(); }; - if( !opt_contentHTML && opt_contentHTML !== '' ) return this; + if( !X_Type_isString( opt_contentHTML ) ) return this; this._contentHTML = opt_contentHTML; if( !( X_UA[ 'IE' ] < 9 ) ){ X_Util_NinjaIframe_writeToIframe( this ); - this._ready = true; }; return this; @@ -103,11 +123,10 @@ function X_Util_NinjaIframe_handleEvent( e ){ // こちらに名前をsetしないとtargetが動作しない if( X_UA[ 'IE' ] ) this._iwin.name = this._name; - this[ 'listen' ]( [ X_UA[ 'IE' ] < 9 ? 'readystatechange' : 'load', 'error' ], this, X_Util_NinjaIframe_handleEvent ); + this[ 'listen' ]( X_UA[ 'IE' ] < 9 ? 'readystatechange' : [ 'load', 'error' ], X_Util_NinjaIframe_handleEvent ); if( !( X_UA[ 'IE' ] < 9 ) ){ - ( this._contentHTML || this._contentHTML === '' ) && X_Util_NinjaIframe_writeToIframe( this ); - this._ready = true; + X_Util_NinjaIframe_writeToIframe( this ); return; }; //break; これあると IE8 で駄目! @@ -116,8 +135,7 @@ function X_Util_NinjaIframe_handleEvent( e ){ if( ( raw.readyState !== 'complete' && raw.readyState !== 'loaded' ) ) break; // ie9- if( !this._ready ){ - ( this._contentHTML || this._contentHTML === '' ) && X_Util_NinjaIframe_writeToIframe( this ); - this._ready = true; + X_Util_NinjaIframe_writeToIframe( this ); break; }; // onload @@ -144,7 +162,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();