X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F05_util%2F01_XNinjaIframe.js;h=3bd2e4c5a4bb03b374a5b673440f7df4f598f41d;hb=d3d95fb0bc2ab2f61c7f15746b2d64078ef39af8;hp=f400818e80357d52a73086a1e017daff5efef271;hpb=f01f21c6d473692d016cb2b286a61d55380be3b3;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 f400818..3bd2e4c 100644 --- a/0.6.x/js/05_util/01_XNinjaIframe.js +++ b/0.6.x/js/05_util/01_XNinjaIframe.js @@ -1,24 +1,46 @@ -/* +/** * http://msdn.microsoft.com/ja-jp/library/ie/hh180174%28v=vs.85%29.aspx * 孤立するとウィンドウ オブジェクトのプロパティが消去される * * http://qiita.com/sou/items/3380d4fa9b08b27bb387 * モバイルブラウザでの iframe の挙動(Mobile Safari, Chrome for Android) + * + * @alias X.Util.NinjaIframe + * @class NinjaIframe 隠し iframe 機能を提供します。 + * @extends {Node} */ - -// TODO Node.inherits -X[ 'Util' ][ 'NinjaIframe' ] = Node[ 'inherits' ]( +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 @@ -50,11 +72,17 @@ 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; @@ -72,18 +100,15 @@ X[ 'Util' ][ 'NinjaIframe' ] = Node[ 'inherits' ]( this._iwin.location.reload(); }; - if( !opt_contentHTML ) return this; + if( !X_Type_isString( opt_contentHTML ) ) return this; this._contentHTML = opt_contentHTML; - X_UA[ 'IE' ] < 9 || X_Util_NinjaIframe_writeToIframe( this ); + + if( !( X_UA[ 'IE' ] < 9 ) ){ + X_Util_NinjaIframe_writeToIframe( this ); + }; return this; - }, - - 'close' : function(){ - X_ViewPort[ 'unlisten' ]( X_EVENT_AFTER_UPDATE, this, X_Util_NinjaIframe_handleEvent ); - this.call( 'close' ); - this[ 'kill' ](); } } @@ -100,11 +125,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 && X_Util_NinjaIframe_writeToIframe( this ); - this._ready = true; + X_Util_NinjaIframe_writeToIframe( this ); return; }; //break; これあると IE8 で駄目! @@ -113,31 +137,35 @@ function X_Util_NinjaIframe_handleEvent( e ){ if( ( raw.readyState !== 'complete' && raw.readyState !== 'loaded' ) ) break; // ie9- if( !this._ready ){ - this._contentHTML && X_Util_NinjaIframe_writeToIframe( this ); - this._ready = true; + X_Util_NinjaIframe_writeToIframe( this ); break; }; // onload case 'load' : console.log( 'iframe load.' ); - this[ 'asyncDispatch' ]( X_EVENT_SUCCESS ); + this[ 'asyncDispatch' ]( 'ninjaload' ); break; case 'error' : - this[ 'asyncDispatch' ]( X_EVENT_ERROR ); + this[ 'asyncDispatch' ]( 'ninjaerror' ); + break; + + case X_EVENT_KILL_INSTANCE : + X_ViewPort[ 'unlisten' ]( X_EVENT_AFTER_UPDATE, this, X_Util_NinjaIframe_handleEvent ); + this._iwin && this._iwin.close(); break; }; - return X_Callback_STOP_PROPAGATION; + return X_CALLBACK_STOP_PROPAGATION; }; function X_Util_NinjaIframe_writeToIframe( that ){ var raw = that[ '_rawObject' ], idoc = raw.contentDocument || that._iwin.document, html = that._contentHTML; - + + that._ready = true; // これを削除すると ie6,7,8 で Stack overflow at line : 0 意味不明 'readystatechange' が繰り返し起こりループする?? delete that._contentHTML; - that._ready = true; idoc.open(); idoc.writeln( html );