X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;ds=sidebyside;f=0.6.x%2Fjs%2F05_util%2F01_XNinjaIframe.js;h=c0a77d1d435eff5f2789e7269df347a529e42433;hb=ef25747bebf1799d49f9bd0d64e339da9ea61d13;hp=2eeaaa9ca372439bef8bde50c16de49a5443823e;hpb=50462b7b22a3c42bdbf2fb84d782937f817368f4;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 2eeaaa9..c0a77d1 100644 --- a/0.6.x/js/05_util/01_XNinjaIframe.js +++ b/0.6.x/js/05_util/01_XNinjaIframe.js @@ -1,27 +1,50 @@ -/* +/** * 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 - X_Node_newByTag = true; - this[ 'Super' ]( 'IFRAME', { @@ -47,11 +70,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; @@ -69,18 +98,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' ](); } } @@ -97,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 && X_Util_NinjaIframe_writeToIframe( this ); - this._ready = true; + X_Util_NinjaIframe_writeToIframe( this ); return; }; //break; これあると IE8 で駄目! @@ -110,31 +135,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 );