1 X.Util.NinjaIframe = X.EventDispatcher.inherits(
\r
14 Constructor : function( html ){
\r
16 this._name = 'hidden-iframe-' + X.getTime();
\r
17 // https://github.com/polygonplanet/Pot.js/blob/master/src/Worker.js
\r
19 this.xnodeIframe = X.Dom.Node._body.create(
\r
22 className : 'hidden-iframe',
\r
25 allowtransparency : 'no',
\r
31 X.Dom.listenOnce( X.Dom.Event.AFTER_UPDATE, this );
\r
33 // http://nanto.asablo.jp/blog/2011/12/08/6237308
\r
34 // IE 6/7 で文書間通信を実現するための一案
\r
36 this.xnodeIframe.attr( 'src', 'about:blank' );
\r
38 // Safari 2.0.* bug: iframe's absolute position and src set.
\r
40 this.xnodeIframe.css( { position : 'absolute' } );
\r
43 if( html ) this._html = html;
\r
46 handleEvent : function( e ){
\r
47 var raw = this.xnodeIframe._rawObject,
\r
51 case X.Dom.Event.AFTER_UPDATE :
\r
53 console.log( 'X.Dom.Event.AFTER_UPDATE' );
\r
54 this._iwin = raw.contentWindow || raw.contentDocument && raw.contentDocument.parentWindow || window.frames[ this._name ];
\r
56 this.xnodeIframe.listen( X.UA.IE < 9 ? [ 'readystatechange', 'error' ] : [ 'load', 'error' ], this );
\r
58 if( !( X.UA.IE < 9 ) ){
\r
59 this._html && X_Util_NinjaIframe_writeToIframe( this );
\r
64 case 'readystatechange' :
\r
65 //alert( 'iframe readystatechange. ' + raw.readyState );
\r
67 if( ( raw.readyState !== 'complete' && raw.readyState !== 'loaded' ) ) return X.Callback.STOP_PROPAGATION;
\r
70 this._html && X_Util_NinjaIframe_writeToIframe( this );
\r
76 console.log( 'iframe load.' );
\r
77 this.asyncDispatch( 0, X.Event.SUCCESS );
\r
80 this.asyncDispatch( 0, X.Event.ERROR );
\r
84 return X.Callback.STOP_PROPAGATION;
\r
87 refresh : function( opt_html ){
\r
88 var raw = this.xnodeIframe._rawObject,
\r
91 this._ready = false;
\r
94 this._html = opt_html;
\r
98 if( X.UA.IE5 || X.UA.IE55 ){
\r
99 this._iwin.location.href = 'about:blank'; // reload() では、IE5.5(IETester)で2回目移行の操作でerrorが出る(doc取得やopen,writeで)
\r
101 this._iwin.location.reload();
\r
104 if( !opt_html ) return this;
\r
107 //if( 7 < X.UA.IE ){
\r
108 this._html = opt_html;
\r
111 this._html = opt_html;
\r
112 X_Util_NinjaIframe_writeToIframe( this );
\r
117 close : function(){
\r
118 X.Dom.unlisten( X.Dom.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
132 that._ready = true;
\r
135 idoc.writeln( html );
\r