2 * Operaでも非同期リクエストが並列処理できる img-JSONP
3 * http://developer.cybozu.co.jp/takesako/2007/06/opera_img-jsonp.html
5 * IE9でiframe内で遷移した場合window.parentのメソッドを呼べない
6 * http://kozo002.blogspot.jp/2012/07/ie9iframewindowparent.html
10 cb : function( accessKey, jsonString, time, opt_json2FileSize ){
11 if( accessKey !== X_NET_JSONP_ACCESS_KEY ) return;
15 type : jsonString ? X.Event.SUCCESS : X.Event.ERROR,
16 data : jsonString //eval( jsonString )
19 console.log( 'ms : ' + time + ' speed : ' + ( ( jsonString.length + ( opt_json2FileSize || 0 ) ) / time * 1000 ) + ' バイト/秒.' );
23 var X_NET_JSONP_ACCESS_KEY = Math.random(),
25 X_NET_JSONP_NinjaIframe,
27 X_NET_JSONP_imageFixListener = X.UA.Opera && function( e ){
29 case X.Event.SUCCESS :
31 X_NET_JSONP_loadScriptInNinjaIframe( e.src );
32 case X.Event.TIMEOUT :
33 case X.Event.CANCELED :
37 function X_NET_JSONP_loadScriptInNinjaIframe( url ){
38 X_NET_JSONP_NinjaIframe || ( X_NET_JSONP_NinjaIframe = new X.Util.NinjaIframe() );
40 var json2Path = 'js/libs/json2.js',
41 json2FileSize = 18103,
46 // http://blog.livedoor.jp/dankogai/archives/51503830.html
47 // Ajax - IE8にもJSON入ってます。使えるとは限らないけど
48 // Compatibility mode (別名Quirks mode) では、JSONオブジェクトは無効になります。iframeもだめです
49 /* 以下のコードは XP ie8 では動くけど、win8 IE11(8モード)で動かない 開発の便宜を取って,setTimeout を挟む
51 'function cb(o){window.parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',window.parent.JSON.stringify(o))}',
53 '<script src="', url, '"></script>' */
54 '<script id="jp"></script>',
56 'function cb(o){nw-=+new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',parent.JSON.stringify(o),-nw)}',
57 'function tm(){jp.src="', url ,'";nw=+new Date}',
64 '<script id="jp"></script>',
66 'function cb(o){nw-=+new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw)}',
67 'function tm(){jp.src="', url ,'";nw=+new Date}',
72 if( window[ 'JSON' ] ){
76 'function cb(o){nw-=+new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw)}',
78 '<script src="', url, '"></script>'
81 if( X.UA.IE < 5 || X.UA.MacIE ){
83 '<script id="jn"></script>',
84 '<script id="jp"></script>',
86 'function cb(o){nw-=new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw-16,', json2FileSize, ')}',
87 'function t1(){document.all.jn.src="', json2Path ,'";setTimeout("t2()",16);nw=+new Date}',
88 'setTimeout("t1()",16);',
89 'function t2(){if(window.JSON){document.all.jp.src="', url ,'"}else{setTimeout("t2()",16)}}',
93 if( X.UA.IE < 8 ){ // ie5-7
95 '<script id="jn"></script>',
96 '<script id="jp"></script>',
98 'function cb(o){nw-=new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw-16,', json2FileSize, ')}',
99 'function t1(){jn.src="', json2Path ,'";setTimeout(t2,16);nw=+new Date}',
100 'setTimeout(t1,16);',
101 'function t2(){if(window.JSON){jp.src="', url ,'"}else{setTimeout(t2,16)}}',
107 'function cb(o){nw-=new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw,', json2FileSize, ')}',
110 '<script src="', json2Path, '"></script>',
111 '<script src="', url, '"></script>'
115 X_NET_JSONP_NinjaIframe
116 .refresh( html.join( '' ) )
117 .listen( [ X.Event.SUCCESS, X.Event.ERROR ], X_NET_JSONPWrapper, X_NET_JSONP_iframeListener );
121 function X_NET_JSONP_iframeListener( e ){
123 case X.Event.SUCCESS :
124 console.log( 'iframe onload' );
128 console.log( 'iframe onerror' );
129 X_NET_JSONPWrapper.asyncDispatch( 0, X.Event.ERROR );
135 X_NET_JSONPWrapper = X.Class._override(
136 new X.EventDispatcher(),
139 _operaImage : null, // X.Dom.Image.Loader();
143 load : function( url, data, timeout ){
146 if( X_NET_JSONP_imageFixListener ){
147 this._operaImage = X.Dom.Image.Loader( url )
148 .listenOnce( [ X.Event.SUCCESS, X.Event.ERROR ], X_NET_JSONP_imageFixListener );
150 X_NET_JSONP_loadScriptInNinjaIframe( url );
157 if( this._operaImage ){
161 delete this._operaImage;
163 this._canceled = true;
168 this._busy = this._canceled = false;