X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;ds=sidebyside;f=0.6.x%2Fjs%2F06_net%2F02_XNetJSONP.js;h=ed9b2d315e18f3c5c755cb904473f61df773876c;hb=HEAD;hp=6918382fca9c30cc5af08df466a2a8038ab54bcd;hpb=0a4e04fb0af6e1b2e452d1a8c0822e723d32a0ee;p=pettanr%2FclientJs.git
diff --git a/0.6.x/js/06_net/02_XNetJSONP.js b/0.6.x/js/06_net/02_XNetJSONP.js
index 6918382..ed9b2d3 100644
--- a/0.6.x/js/06_net/02_XNetJSONP.js
+++ b/0.6.x/js/06_net/02_XNetJSONP.js
@@ -1,10 +1,11 @@
+//{+jsonp"jsonpã«ããajax"(jsonpã«ããã¯ãã¹ãã¡ã¤ã³éä¿¡ã)[+net,+ninjaiframe]
+
/*
* Operaã§ãéåæãªã¯ã¨ã¹ãã並åå¦çã§ãã img-JSONP
* 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
*
@@ -23,42 +24,43 @@
// TODO iframe useful or not. TODO check dynamicIframe
// TODO file: ã§ã¯ãhttp: ã¯ä½¿ããªã
-X[ 'Net' ][ 'JSONP' ] = {
- 'cb' : function( accessKey, jsonString, time, opt_json2FileSize ){
- if( accessKey !== X_NET_JSONP_ACCESS_KEY || !X_NET_JSONPWrapper._busy ) return;
+X_TEMP.X_JSONP_cb = function( accessKey, jsonString, time, opt_json2FileSize ){
+ if( accessKey !== X_JSONP_ACCESS_KEY || !X_JSONP._busy ) return;
- X_NET_JSONPWrapper._busy = false;
+ X_JSONP._busy = false;
- X_NET_JSONPWrapper
+ X_JSONP
[ 'asyncDispatch' ]( {
- type : jsonString ? X_EVENT_SUCCESS : X_EVENT_ERROR,
- data : X_String_parseTrustedJsonString( jsonString )
+ type : jsonString ? X_EVENT_SUCCESS : X_EVENT_ERROR,
+ response : X_JSON_parseTrustableString( jsonString )
} );
- X_Net_JSONP_errorTimerID && X_Timer_remove( X_Net_JSONP_errorTimerID );
+ X_JSONP_errorTimerID && X_Timer_remove( X_JSONP_errorTimerID );
console.log( 'ms : ' + time + ' speed : ' + ( ( jsonString.length + ( opt_json2FileSize || 0 ) ) / time * 1000 ) + ' ãã¤ã/ç§.' );
- }
-};
+ };
-var X_NET_JSONP_ACCESS_KEY = Math.random(),
+var X_JSONP_ACCESS_KEY = Math.random(),
- X_Net_JSONP_maxOnloadCount,
+ X_JSONP_maxOnloadCount,
- X_Net_JSONP_onloadCount = 0,
+ X_JSONP_onloadCount = 0,
- X_Net_JSONP_errorTimerID;
+ X_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_TEMP.X_JSONP_init = function(){
+ X[ 'Net' ][ '__json_cb__' ] = X_TEMP.X_JSONP_cb;
+
+ X_JSONP = X_Class_override( X_NinjaIframe(), X_TEMP.X_JSONP_params );
- delete X_TEMP.X_NET_JSONP_init;
- delete X_TEMP.X_NET_JSONP_params;
+ delete X_TEMP.X_JSONP_cb;
+ delete X_TEMP.X_JSONP_init;
+ delete X_TEMP.X_JSONP_params;
- return X_NET_JSONPWrapper;
+ return X_JSONP;
};
-X_TEMP.X_NET_JSONP_params = {
+X_TEMP.X_JSONP_params = {
_busy : false,
_canceled : false,
@@ -66,16 +68,18 @@ X_TEMP.X_NET_JSONP_params = {
load : function( option ){
//createURL
var url = option[ 'url' ],
- params = option[ 'params' ],
callback = option[ 'callbackName' ],
charset = option[ 'charset' ],
json2Path = window.RegExp ? 'js/libs/json2.js' : 'js/libs/json2_regfree.js',
json2FileSize = 18103,
html;
- url = X_URL_create( url, params );
-
- if( !callback && !( callback = X_URL_ParamToObj( url.split( '?' )[ 1 ] )[ 'callback' ] ) ){
+ // file ãããã³ã«ã§å¤é¨ã¢ã¯ã»ã¹ã®ç¦æ¢
+ if( !X_URL_isSameProtocol( url ) ){
+ return X_JSONP[ 'asyncDispatch' ]( X_EVENT_ERROR );
+ };
+
+ if( !callback && !( callback = X_URL_paramToObj( url.split( '?' )[ 1 ] )[ 'callback' ] ) ){
url += '&callback=cb';
callback = 'cb';
};
@@ -93,61 +97,55 @@ X_TEMP.X_NET_JSONP_params = {
'',
'',
''
];
- X_Net_JSONP_maxOnloadCount = 2;
+ X_JSONP_maxOnloadCount = 2;
} else
if( X_UA[ 'IE8' ] ){
html = [
- // JavaScriptã§unicodeæååãunescapeãã
- // http://perutago.seesaa.net/article/202801583.html
-
- // http://blog.livedoor.jp/dankogai/archives/51503830.html
- // Ajax - IE8ã«ãJSONå
¥ã£ã¦ã¾ãã使ããã¨ã¯éããªããã©
- // Compatibility mode (å¥åQuirks mode) ã§ã¯ãJSONãªãã¸ã§ã¯ãã¯ç¡å¹ã«ãªãã¾ããiframeãã ãã§ã
'',
''
/*ã以ä¸ã®ã³ã¼ã㯠XP ie8 ã§ã¯åããã©ãwin8 IE11(8ã¢ã¼ã)ã§åããªã éçºã®ä¾¿å®ãåã£ã¦,setTimeout ãæã
'',
'' */
];
- X_Net_JSONP_maxOnloadCount = 2;
+ X_JSONP_maxOnloadCount = 2;
} else
if( X_UA[ 'IE9' ] ){
html = [
'',
''
];
- X_Net_JSONP_maxOnloadCount = 2;
+ X_JSONP_maxOnloadCount = 2;
} else
if( window[ 'JSON' ] ){
html = [
'',
''
];
- X_Net_JSONP_maxOnloadCount = 1;
+ X_JSONP_maxOnloadCount = 1;
} else
if( X_UA[ 'IE4' ] || X_UA[ 'MacIE' ] ){
html = [
@@ -155,13 +153,13 @@ X_TEMP.X_NET_JSONP_params = {
'',
''
];
- X_Net_JSONP_maxOnloadCount = 3;
+ X_JSONP_maxOnloadCount = 3;
} else
if( X_UA[ 'IE' ] < 8 ){ // ie5-7
html = [
@@ -169,59 +167,59 @@ X_TEMP.X_NET_JSONP_params = {
'',
''
];
- X_Net_JSONP_maxOnloadCount = 3;
+ X_JSONP_maxOnloadCount = 3;
} else {
html = [
'',
'',
''
];
- X_Net_JSONP_maxOnloadCount = 2;
+ X_JSONP_maxOnloadCount = 2;
};
- X_NET_JSONPWrapper
+ X_JSONP
[ 'refresh' ]( html.join( '' ) )
- [ 'listen' ]( [ 'ninjaload', 'ninjaerror' ], X_NET_JSONP_iframeListener );
+ [ 'listen' ]( [ 'ninjaload', 'ninjaerror' ], X_JSONP_iframeListener );
- X_NET_JSONPWrapper._busy = true;
+ X_JSONP._busy = true;
},
cancel : function(){
- X_NET_JSONPWrapper.reset();
- X_NET_JSONPWrapper._canceled = true;
+ X_JSONP.reset();
+ X_JSONP._canceled = true;
},
reset : function(){
- X_NET_JSONPWrapper._busy = X_NET_JSONPWrapper._canceled = false;
- X_NET_JSONPWrapper[ 'unlisten' ]( [ 'ninjaload', 'ninjaerror' ], X_NET_JSONP_iframeListener );
- X_NET_JSONPWrapper[ 'refresh' ]( '' );
- X_Net_JSONP_errorTimerID && X_Timer_remove( X_Net_JSONP_errorTimerID );
- X_Net_JSONP_errorTimerID = X_Net_JSONP_onloadCount = 0;
+ X_JSONP._busy = X_JSONP._canceled = false;
+ X_JSONP[ 'unlisten' ]( [ 'ninjaload', 'ninjaerror' ], X_JSONP_iframeListener );
+ X_JSONP[ 'refresh' ]( '' );
+ X_JSONP_errorTimerID && X_Timer_remove( X_JSONP_errorTimerID );
+ X_JSONP_errorTimerID = X_JSONP_onloadCount = 0;
}
};
-function X_NET_JSONP_iframeListener( e ){
+function X_JSONP_iframeListener( e ){
switch( e.type ){
case 'ninjaload' :
- console.log( 'iframe onload, but ' + X_Net_JSONP_onloadCount + ' < ' + X_Net_JSONP_maxOnloadCount );
- if( ++X_Net_JSONP_onloadCount < X_Net_JSONP_maxOnloadCount ) return;
+ console.log( 'iframe onload, but ' + X_JSONP_onloadCount + ' < ' + X_JSONP_maxOnloadCount );
+ if( ++X_JSONP_onloadCount < X_JSONP_maxOnloadCount ) return;
// TODO callback ãç¡ããã° error -> timeout ã観ã?
- X_Net_JSONP_errorTimerID = X_NET_JSONPWrapper[ 'asyncDispatch' ]( 1000, X_EVENT_ERROR );
+ X_JSONP_errorTimerID = X_JSONP[ 'asyncDispatch' ]( 1000, X_EVENT_ERROR );
break;
case 'ninjaerror' :
console.log( 'iframe onerror' );
- X_NET_JSONPWrapper[ 'asyncDispatch' ]( X_EVENT_ERROR );
+ X_JSONP[ 'asyncDispatch' ]( X_EVENT_ERROR );
break;
};
- return X_Callback_UN_LISTEN;
+ return X_CALLBACK_UN_LISTEN;
};