* http://developer.cybozu.co.jp/takesako/2007/06/opera_img-jsonp.html
*
* iframe を使った jsonp の読み込みエラー判定の記事、
- * JSONPのエラーを判断する は web archive でも観れない
- * http://d.hatena.ne.jp/yuushimizu/20090128/1233146321
+ * https://web.archive.org/web/20120917100043/http://d.hatena.ne.jp/yuushimizu/20090128/1233146321
* TODO JSONPの動的取得+エラー処理
* http://d.hatena.ne.jp/NeoCat/20110206/1296934235
*
// TODO iframe useful or not. TODO check dynamicIframe
// TODO file: では http: は使えない
-X[ 'Net' ][ 'JSONP' ] = {
- 'cb' : function( accessKey, jsonString, time, opt_json2FileSize ){
+X_TEMP.X_NET_JSONP_cb = function( accessKey, jsonString, time, opt_json2FileSize ){
if( accessKey !== X_NET_JSONP_ACCESS_KEY || !X_NET_JSONPWrapper._busy ) return;
X_NET_JSONPWrapper._busy = false;
X_NET_JSONPWrapper
[ 'asyncDispatch' ]( {
type : jsonString ? X_EVENT_SUCCESS : X_EVENT_ERROR,
- response : X_String_parseTrustedJsonString( jsonString )
+ response : X_JSON_parseTrustableString( jsonString )
} );
X_Net_JSONP_errorTimerID && X_Timer_remove( X_Net_JSONP_errorTimerID );
console.log( 'ms : ' + time + ' speed : ' + ( ( jsonString.length + ( opt_json2FileSize || 0 ) ) / time * 1000 ) + ' バイト/秒.' );
- }
-};
+ };
var X_NET_JSONP_ACCESS_KEY = Math.random(),
X_Net_JSONP_errorTimerID;
X_TEMP.X_NET_JSONP_init = function(){
- X_NET_JSONPWrapper = X_Class_override( X[ 'Util' ][ 'NinjaIframe' ](), X_TEMP.X_NET_JSONP_params );
+ X[ 'Net' ][ '__json_cb__' ] = X_TEMP.X_NET_JSONP_cb;
+
+ X_NET_JSONPWrapper = X_Class_override( X_NinjaIframe(), X_TEMP.X_NET_JSONP_params );
+ delete X_TEMP.X_NET_JSONP_cb;
delete X_TEMP.X_NET_JSONP_init;
delete X_TEMP.X_NET_JSONP_params;
url = X_URL_create( url, params );
- if( !callback && !( callback = X_URL_ParamToObj( url.split( '?' )[ 1 ] )[ 'callback' ] ) ){
+ if( !callback && !( callback = X_URL_paramToObj( url.split( '?' )[ 1 ] )[ 'callback' ] ) ){
url += '&callback=cb';
callback = 'cb';
};
'<script>',
'onunload=function(){im.onload=im.onerror=""};',
'nw=+new Date;',
- 'function ', callback, '(o){if(nw){nw-=+new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw', window[ 'JSON' ] ? json2FileSize : 0 ,');nw=0}}',
+ 'function ', callback, '(o){if(nw){nw-=+new Date;parent.X.Net.__json_cb__(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw', window[ 'JSON' ] ? json2FileSize : 0 ,');nw=0}}',
'</script>',
'<script', charset, ' id="jp"></script>',
'<img id="im" src="', url, '" onload="jp.src=im.src" onerror="jp.src=im.src">'
'<script>',
'onunload=function(){clearTimeout(id)};',
'nw=0;', // なぜか必要,,,
- 'function ', callback, '(o){nw-=+new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',parent.X.JSON.stringify(o),-nw)}',
+ 'function ', callback, '(o){nw-=+new Date;parent.X.Net.__json_cb__(' + X_NET_JSONP_ACCESS_KEY + ',parent.X.JSON.stringify(o),-nw)}',
//'function ', callback, '(o){if(nw){nw-=+new Date;postMessage("', X_NET_JSONP_SEND_MSG_KEY,' "+nw+"|"+parent.JSON.stringify(o).replace(/\\\\u([a-fA-F0-9]{4})/g,function(a,b){return String.fromCharCode(parseInt(b,16))}),"*");nw=0}}',
'function tm(){jp.src="', url ,'";nw=+new Date}',
'id=setTimeout(tm,16);',
/* 以下のコードは XP ie8 では動くけど、win8 IE11(8モード)で動かない 開発の便宜を取って,setTimeout を挟む
'<script>',
- 'function ', callback, '(o){window.parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',window.parent.JSON.stringify(o))}',
+ 'function ', callback, '(o){window.parent.X.Net.__json_cb__(' + X_NET_JSONP_ACCESS_KEY + ',window.parent.JSON.stringify(o))}',
'</script>',
'<script src="', url, '"></script>' */
];
'<script', charset, ' id="jp"></script>',
'<script>',
'onunload=function(){clearTimeout(id)};',
- 'function ', callback, '(o){nw-=+new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw)}',
+ 'function ', callback, '(o){nw-=+new Date;parent.X.Net.__json_cb__(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw)}',
'function tm(){jp.src="', url ,'";nw=+new Date}',
'id=setTimeout(tm,16);',
'</script>'
html = [
'<script>',
'nw=+new Date;',
- 'function ', callback, '(o){if(nw){nw-=+new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw);nw=0}}',
+ 'function ', callback, '(o){if(nw){nw-=+new Date;parent.X.Net.__json_cb__(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw);nw=0}}',
//'function ', callback, '(o){if(nw){nw-=+new Date;parent.postMessage("', X_NET_JSONP_SEND_MSG_KEY,' "+nw+"|"+JSON.stringify(o),"', location.origin, '");nw=0}}',
'</script>',
'<script', charset, ' src="', url, '"></script>'
'<script', charset, ' id="jp"></script>',
'<script>',
'onunload=function(){clearTimeout(id)};',
- 'function ', callback, '(o){nw-=new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw-16,', json2FileSize, ')}',
+ 'function ', callback, '(o){nw-=new Date;parent.X.Net.__json_cb__(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw-16,', json2FileSize, ')}',
'function t1(){document.all.jn.src="', json2Path ,'";id=setTimeout("t2()",16);nw=+new Date}',
'id=setTimeout("t1()",16);',
'function t2(){if(window.JSON){document.all.jp.src="', url ,'"}else{id=setTimeout("t2()",16)}}',
'<script', charset, ' id="jp"></script>',
'<script>',
'onunload=function(){clearTimeout(id)};',
- 'function ', callback, '(o){nw-=new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw-16,', json2FileSize, ')}',
+ 'function ', callback, '(o){nw-=new Date;parent.X.Net.__json_cb__(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw-16,', json2FileSize, ')}',
'function t1(){jn.src="', json2Path ,'";id=setTimeout(t2,16);nw=+new Date}',
'id=setTimeout(t1,16);',
'function t2(){if(window.JSON){jp.src="', url ,'"}else{id=setTimeout(t2,16)}}',
} else {
html = [
'<script>',
- 'function ', callback, '(o){if(nw){nw-=new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw,', json2FileSize, ');nw=0}}',
+ 'function ', callback, '(o){if(nw){nw-=new Date;parent.X.Net.__json_cb__(' + X_NET_JSONP_ACCESS_KEY + ',JSON.stringify(o),-nw,', json2FileSize, ');nw=0}}',
'nw=+new Date;',
'</script>',
'<script src="', json2Path, '"></script>',
X_NET_JSONPWrapper[ 'asyncDispatch' ]( X_EVENT_ERROR );
break;
};
- return X_Callback_UN_LISTEN;
+ return X_CALLBACK_UN_LISTEN;
};