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;
13 X_NET_JSONPWrapper._busy = false;
17 type : jsonString ? X.Event.SUCCESS : X.Event.ERROR,
18 data : jsonString //eval( jsonString )
21 console.log( 'ms : ' + time + ' speed : ' + ( ( jsonString.length + ( opt_json2FileSize || 0 ) ) / time * 1000 ) + ' バイト/秒.' );
25 var X_NET_JSONP_ACCESS_KEY = Math.random(),
27 X_NET_JSONP_NinjaIframe;
30 function X_NET_JSONP_operaImageHandleEvent( e ){
32 case X.Event.SUCCESS :
34 X_NET_JSONP_loadScriptInNinjaIframe( e.src );
36 case X.Event.TIMEOUT :
37 case X.Event.CANCELED :
38 X_NET_JSONPWrapper._operaImage.unlisten().reset();
39 X_NET_JSONPWrapper.asyncDispatch( 0, X.Event.ERROR );
43 if( !X.UA.Opera ) X_NET_JSONP_operaImageHandleEvent = null;
46 function X_NET_JSONP_loadScriptInNinjaIframe( url ){
47 var json2Path = 'js/libs/json2.js',
48 json2FileSize = 18103,
51 X_NET_JSONP_NinjaIframe || ( X_NET_JSONP_NinjaIframe = new X.Util.NinjaIframe() );
55 // http://blog.livedoor.jp/dankogai/archives/51503830.html
56 // Ajax - IE8にもJSON入ってます。使えるとは限らないけど
57 // Compatibility mode (別名Quirks mode) では、JSONオブジェクトは無効になります。iframeもだめです
58 /* 以下のコードは XP ie8 では動くけど、win8 IE11(8モード)で動かない 開発の便宜を取って,setTimeout を挟む
60 'function cb(o){window.parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',window.parent.JSON.stringify(o))}',
62 '<script src="', url, '"></script>' */
63 '<script id="jp"></script>',
65 'function cb(o){nw-=+new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',parent.JSON.stringify(o),-nw)}',
66 'function tm(){jp.src="', url ,'";nw=+new Date}',
73 '<script id="jp"></script>',
75 'function cb(o){nw-=+new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw)}',
76 'function tm(){jp.src="', url ,'";nw=+new Date}',
81 if( window[ 'JSON' ] ){
85 'function cb(o){nw-=+new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw)}',
87 '<script src="', url, '"></script>'
90 if( X.UA.IE < 5 || X.UA.MacIE ){
92 '<script id="jn"></script>',
93 '<script id="jp"></script>',
95 'function cb(o){nw-=new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw-16,', json2FileSize, ')}',
96 'function t1(){document.all.jn.src="', json2Path ,'";setTimeout("t2()",16);nw=+new Date}',
97 'setTimeout("t1()",16);',
98 'function t2(){if(window.JSON){document.all.jp.src="', url ,'"}else{setTimeout("t2()",16)}}',
102 if( X.UA.IE < 8 ){ // ie5-7
104 '<script id="jn"></script>',
105 '<script id="jp"></script>',
107 'function cb(o){nw-=new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw-16,', json2FileSize, ')}',
108 'function t1(){jn.src="', json2Path ,'";setTimeout(t2,16);nw=+new Date}',
109 'setTimeout(t1,16);',
110 'function t2(){if(window.JSON){jp.src="', url ,'"}else{setTimeout(t2,16)}}',
116 'function cb(o){nw-=new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw,', json2FileSize, ')}',
119 '<script src="', json2Path, '"></script>',
120 '<script src="', url, '"></script>'
124 X_NET_JSONP_NinjaIframe
125 .refresh( html.join( '' ) )
126 .listen( [ X.Event.SUCCESS, X.Event.ERROR ], X_NET_JSONPWrapper, X_NET_JSONP_iframeListener );
130 function X_NET_JSONP_iframeListener( e ){
132 case X.Event.SUCCESS :
133 console.log( 'iframe onload' );
137 console.log( 'iframe onerror' );
138 X_NET_JSONPWrapper.asyncDispatch( 0, X.Event.ERROR );
144 X_NET_JSONPWrapper = X.Class._override(
145 new X.EventDispatcher(),
148 _operaImage : null, // X.Net.Image();
152 load : function( url, data, timeout ){
154 if( X_NET_JSONP_operaImageHandleEvent ){
155 this._operaImage = X.Net.Image( url )
156 .listenOnce( [ X.Event.SUCCESS, X.Event.ERROR ], X_NET_JSONP_operaImageHandleEvent );
158 X_NET_JSONP_loadScriptInNinjaIframe( url );
165 if( this._operaImage ){
169 delete this._operaImage;
171 this._canceled = true;
176 this._busy = this._canceled = false;