OSDN Git Service

Version 0.6.157, add X.Net.Form & fix X.EventDispatcher.
[pettanr/clientJs.git] / 0.6.x / js / 05_util / 01_XNinjaIframe.js
index 2eeaaa9..8507c5e 100644 (file)
@@ -1,6 +1,9 @@
 /*\r
  * http://msdn.microsoft.com/ja-jp/library/ie/hh180174%28v=vs.85%29.aspx\r
  * 孤立するとウィンドウ オブジェクトのプロパティが消去される\r
+ * \r
+ * http://qiita.com/sou/items/3380d4fa9b08b27bb387\r
+ * モバイルブラウザでの iframe の挙動(Mobile Safari, Chrome for Android)\r
  */\r
 \r
 // TODO Node.inherits\r
@@ -69,14 +72,19 @@ X[ 'Util' ][ 'NinjaIframe' ] = Node[ 'inherits' ](
                                this._iwin.location.reload();\r
                        };\r
                        \r
-                       if( !opt_contentHTML ) return this;\r
+                       if( !opt_contentHTML && opt_contentHTML !== '' ) return this;\r
                        \r
                        this._contentHTML = opt_contentHTML;\r
-                       X_UA[ 'IE' ] < 9 || X_Util_NinjaIframe_writeToIframe( this );\r
+\r
+                       if( !( X_UA[ 'IE' ] < 9 ) ){\r
+                               X_Util_NinjaIframe_writeToIframe( this );\r
+                               this._ready = true;\r
+                       };\r
                        \r
                        return this;\r
                },\r
                \r
+               // TODO close -> kill\r
                'close' : function(){\r
                        X_ViewPort[ 'unlisten' ]( X_EVENT_AFTER_UPDATE, this, X_Util_NinjaIframe_handleEvent );\r
                        this.call( 'close' );\r
@@ -100,7 +108,7 @@ function X_Util_NinjaIframe_handleEvent( e ){
                        this[ 'listen' ]( [ X_UA[ 'IE' ] < 9 ? 'readystatechange' : 'load', 'error' ], this, X_Util_NinjaIframe_handleEvent );\r
                        \r
                        if( !( X_UA[ 'IE' ] < 9 ) ){\r
-                               this._contentHTML && X_Util_NinjaIframe_writeToIframe( this );\r
+                               ( this._contentHTML || this._contentHTML === '' ) && X_Util_NinjaIframe_writeToIframe( this );\r
                                this._ready = true;\r
                                return;\r
                        };\r
@@ -110,18 +118,18 @@ function X_Util_NinjaIframe_handleEvent( e ){
                        if( ( raw.readyState !== 'complete' && raw.readyState !== 'loaded' ) ) break;\r
                        // ie9-\r
                        if( !this._ready ){\r
-                               this._contentHTML && X_Util_NinjaIframe_writeToIframe( this );\r
+                               ( this._contentHTML || this._contentHTML === '' ) && X_Util_NinjaIframe_writeToIframe( this );\r
                                this._ready = true;\r
                                break;\r
                        };\r
                        // onload\r
                case 'load' :\r
                        console.log( 'iframe load.' );\r
-                       this[ 'asyncDispatch' ]( X_EVENT_SUCCESS );\r
+                       this[ 'asyncDispatch' ]( 'ninjaload' );\r
                        break;\r
 \r
                case 'error' :\r
-                       this[ 'asyncDispatch' ]( X_EVENT_ERROR );\r
+                       this[ 'asyncDispatch' ]( 'ninjaerror' );\r
                        break;\r
        };\r
        \r
@@ -134,7 +142,6 @@ function X_Util_NinjaIframe_writeToIframe( that ){
                html = that._contentHTML;\r
                \r
        delete that._contentHTML;\r
-       that._ready = true;\r
 \r
        idoc.open();\r
        idoc.writeln( html );\r