2 * http://msdn.microsoft.com/ja-jp/library/ie/hh180174%28v=vs.85%29.aspx
\r
3 * 孤立するとウィンドウ オブジェクトのプロパティが消去される
\r
6 // TODO Node.inherits
\r
7 X.Util.NinjaIframe = X.EventDispatcher.inherits(
\r
20 Constructor : function( html ){
\r
22 this._name = 'hidden-iframe-' + X_Timer_now();
\r
23 // https://github.com/polygonplanet/Pot.js/blob/master/src/Worker.js
\r
25 this.xnodeIframe = X_Node_body.create(
\r
28 className : 'hidden-iframe',
\r
30 allowtransparency : 'no',
\r
38 X_ViewPort.listenOnce( X.Event.AFTER_UPDATE, this );
\r
40 // http://nanto.asablo.jp/blog/2011/12/08/6237308
\r
41 // IE 6/7 で文書間通信を実現するための一案
\r
43 this.xnodeIframe.attr( 'src', 'about:blank' );
\r
45 // Safari 2.0.* bug: iframe's absolute position and src set.
\r
47 this.xnodeIframe.css( { position : 'absolute' } );
\r
50 if( html ) this._contentHTML = html;
\r
53 handleEvent : function( e ){
\r
54 var raw = this.xnodeIframe._rawObject;
\r
57 case X.Event.AFTER_UPDATE :
\r
58 this._iwin = raw.contentWindow || ( raw.contentDocument && raw.contentDocument.parentWindow ) || window.frames[ this._name ];
\r
59 // http://d.hatena.ne.jp/NeoCat/20080921/1221940658
\r
60 // こちらに名前をsetしないとtargetが動作しない
\r
61 this._iwin.name = this._name;
\r
63 this.xnodeIframe.listen( [ X_UA.IE < 9 ? 'readystatechange' : 'load', 'error' ], this );
\r
65 if( !( X_UA.IE < 9 ) ){
\r
66 this._contentHTML && X_Util_NinjaIframe_writeToIframe( this );
\r
71 case 'readystatechange' :
\r
72 if( ( raw.readyState !== 'complete' && raw.readyState !== 'loaded' ) ) break;
\r
75 this._contentHTML && X_Util_NinjaIframe_writeToIframe( this );
\r
81 console.log( 'iframe load.' );
\r
82 this.asyncDispatch( X.Event.SUCCESS );
\r
85 this.asyncDispatch( X.Event.ERROR );
\r
89 return X.Callback.STOP_PROPAGATION;
\r
92 refresh : function( opt_contentHTML ){
\r
93 var raw = this.xnodeIframe._rawObject,
\r
96 this._ready = false;
\r
99 this._contentHTML = opt_contentHTML;
\r
103 if( X_UA.IE5 || X_UA.IE55 ){
\r
104 this._iwin.location.href = 'about:blank'; // reload() では、IE5.5(IETester)で2回目移行の操作でerrorが出る(doc取得やopen,writeで)
\r
106 this._iwin.location.reload();
\r
109 if( !opt_contentHTML ) return this;
\r
111 this._contentHTML = opt_contentHTML;
\r
112 X_UA.IE < 9 || X_Util_NinjaIframe_writeToIframe( this );
\r
117 close : function(){
\r
118 X_ViewPort.unlisten( X.Event.AFTER_UPDATE, this );
\r
119 this.xnodeIframe.call( 'close' );
\r
120 this.xnodeIframe.destroy();
\r
126 function X_Util_NinjaIframe_writeToIframe( that ){
\r
127 var raw = that.xnodeIframe._rawObject,
\r
128 idoc = raw.contentDocument || that._iwin.document,
\r
129 html = that._contentHTML;
\r
131 delete that._contentHTML;
\r
132 that._ready = true;
\r
135 idoc.writeln( html );
\r