mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-03-21 17:50:29 -05:00
Remove jQuery-JSON dependency
We now just use JSON.parse and JSON.stringify - it's supported by all browsers supported by the client. Tools.safeJSON has also been moved to Storage.safeJSON, since it's not used in replays at all.
This commit is contained in:
parent
2aa13ed10c
commit
b6dcc4da35
|
|
@ -101,7 +101,6 @@ ga('send', 'pageview');
|
|||
<script src="//play.pokemonshowdown.com/js/lib/jquery-2.1.4.min.js"></script>
|
||||
<script src="//play.pokemonshowdown.com/js/lib/jquery-cookie.js"></script>
|
||||
<script src="//play.pokemonshowdown.com/js/lib/autoresize.jquery.min.js?"></script>
|
||||
<script src="//play.pokemonshowdown.com/js/lib/jquery.json-2.3.min.js"></script>
|
||||
<script src="//play.pokemonshowdown.com/js/lib/soundmanager2-nodebug-jsmin.js?"></script>
|
||||
<script>
|
||||
soundManager.setup({url: '//play.pokemonshowdown.com/swf/'});
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@
|
|||
}
|
||||
|
||||
try {
|
||||
requestData = $.parseJSON(data);
|
||||
requestData = JSON.parse(data);
|
||||
} catch (err) {}
|
||||
return this.receiveRequest(requestData, choiceText);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -773,7 +773,7 @@
|
|||
$.get(app.user.getActionPHP(), {
|
||||
act: 'ladderget',
|
||||
user: targets[0]
|
||||
}, Tools.safeJSON(function (data) {
|
||||
}, Storage.safeJSON(function (data) {
|
||||
if (!data || !$.isArray(data)) return self.add('|raw|Error: corrupted ranking data');
|
||||
var buffer = '<div class="ladder"><table><tr><td colspan="8">User: <strong>' + toName(targets[0]) + '</strong></td></tr>';
|
||||
if (!data.length) {
|
||||
|
|
|
|||
|
|
@ -866,7 +866,7 @@
|
|||
oldpassword: data.oldpassword,
|
||||
password: data.password,
|
||||
cpassword: data.cpassword
|
||||
}, Tools.safeJSON(function (data) {
|
||||
}, Storage.safeJSON(function (data) {
|
||||
if (!data) data = {};
|
||||
if (data.actionsuccess) {
|
||||
app.addPopupMessage("Your password was successfully changed.");
|
||||
|
|
@ -908,7 +908,7 @@
|
|||
cpassword: data.cpassword,
|
||||
captcha: captcha,
|
||||
challstr: app.user.challstr
|
||||
}, Tools.safeJSON(function (data) {
|
||||
}, Storage.safeJSON(function (data) {
|
||||
if (!data) data = {};
|
||||
var token = data.assertion;
|
||||
if (data.curuser && data.curuser.loggedin) {
|
||||
|
|
|
|||
|
|
@ -278,7 +278,7 @@
|
|||
name: name,
|
||||
pass: password,
|
||||
challstr: this.challstr
|
||||
}, Tools.safeJSON(function (data) {
|
||||
}, Storage.safeJSON(function (data) {
|
||||
if (data && data.curuser && data.curuser.loggedin) {
|
||||
// success!
|
||||
self.set('registered', data.curuser);
|
||||
|
|
@ -317,7 +317,7 @@
|
|||
$.post(this.getActionPHP(), {
|
||||
act: 'upkeep',
|
||||
challstr: this.challstr
|
||||
}, Tools.safeJSON(function (data) {
|
||||
}, Storage.safeJSON(function (data) {
|
||||
self.loaded = true;
|
||||
if (!data.username) {
|
||||
app.topbar.updateUserbar();
|
||||
|
|
@ -955,13 +955,13 @@
|
|||
|
||||
case 'updatechallenges':
|
||||
if (this.rooms['']) {
|
||||
this.rooms[''].updateChallenges($.parseJSON(data.substr(18)));
|
||||
this.rooms[''].updateChallenges(JSON.parse(data.substr(18)));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'updatesearch':
|
||||
if (this.rooms['']) {
|
||||
this.rooms[''].updateSearch($.parseJSON(data.substr(14)));
|
||||
this.rooms[''].updateSearch(JSON.parse(data.substr(14)));
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
|||
23
js/lib/jquery.json-2.3.min.js
vendored
23
js/lib/jquery.json-2.3.min.js
vendored
|
|
@ -1,23 +0,0 @@
|
|||
|
||||
(function($){var escapeable=/["\\\x00-\x1f\x7f-\x9f]/g,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};$.toJSON=typeof JSON==='object'&&JSON.stringify?JSON.stringify:function(o){if(o===null){return'null';}
|
||||
var type=typeof o;if(type==='undefined'){return undefined;}
|
||||
if(type==='number'||type==='boolean'){return''+o;}
|
||||
if(type==='string'){return $.quoteString(o);}
|
||||
if(type==='object'){if(typeof o.toJSON==='function'){return $.toJSON(o.toJSON());}
|
||||
if(o.constructor===Date){var month=o.getUTCMonth()+1,day=o.getUTCDate(),year=o.getUTCFullYear(),hours=o.getUTCHours(),minutes=o.getUTCMinutes(),seconds=o.getUTCSeconds(),milli=o.getUTCMilliseconds();if(month<10){month='0'+month;}
|
||||
if(day<10){day='0'+day;}
|
||||
if(hours<10){hours='0'+hours;}
|
||||
if(minutes<10){minutes='0'+minutes;}
|
||||
if(seconds<10){seconds='0'+seconds;}
|
||||
if(milli<100){milli='0'+milli;}
|
||||
if(milli<10){milli='0'+milli;}
|
||||
return'"'+year+'-'+month+'-'+day+'T'+
|
||||
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
|
||||
if(o.constructor===Array){var ret=[];for(var i=0;i<o.length;i++){ret.push($.toJSON(o[i])||'null');}
|
||||
return'['+ret.join(',')+']';}
|
||||
var name,val,pairs=[];for(var k in o){type=typeof k;if(type==='number'){name='"'+k+'"';}else if(type==='string'){name=$.quoteString(k);}else{continue;}
|
||||
type=typeof o[k];if(type==='function'||type==='undefined'){continue;}
|
||||
val=$.toJSON(o[k]);pairs.push(name+':'+val);}
|
||||
return'{'+pairs.join(',')+'}';}};$.evalJSON=typeof JSON==='object'&&JSON.parse?JSON.parse:function(src){return eval('('+src+')');};$.secureEvalJSON=typeof JSON==='object'&&JSON.parse?JSON.parse:function(src){var filtered=src.replace(/\\["\\\/bfnrtu]/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered)){return eval('('+src+')');}else{throw new SyntaxError('Error parsing JSON, source is not valid.');}};$.quoteString=function(string){if(string.match(escapeable)){return'"'+string.replace(escapeable,function(a){var c=meta[a];if(typeof c==='string'){return c;}
|
||||
c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
|
||||
return'"'+string+'"';};})(jQuery);
|
||||
|
|
@ -24,6 +24,14 @@ Storage.initialize = function () {
|
|||
Storage.initPrefs();
|
||||
};
|
||||
|
||||
Storage.safeJSON = function (callback) {
|
||||
return function (data) {
|
||||
if (data.length < 1) return;
|
||||
if (data[0] == ']') data = data.substr(1);
|
||||
return callback(JSON.parse(data));
|
||||
};
|
||||
};
|
||||
|
||||
/*********************************************************
|
||||
* Background
|
||||
*********************************************************/
|
||||
|
|
@ -236,13 +244,13 @@ Storage.prefs = function (prop, value, save) {
|
|||
Storage.prefs.data = {};
|
||||
try {
|
||||
if (window.localStorage) {
|
||||
Storage.prefs.data = $.parseJSON(localStorage.getItem('showdown_prefs')) || {};
|
||||
Storage.prefs.data = JSON.parse(localStorage.getItem('showdown_prefs')) || {};
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
Storage.prefs.save = function () {
|
||||
try {
|
||||
localStorage.setItem('showdown_prefs', $.toJSON(this.data));
|
||||
localStorage.setItem('showdown_prefs', JSON.stringify(this.data));
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
|
|
@ -340,7 +348,7 @@ Storage.onMessage = function ($e) {
|
|||
var data = e.data;
|
||||
switch (data.charAt(0)) {
|
||||
case 'c':
|
||||
Config.server = $.parseJSON(data.substr(1));
|
||||
Config.server = JSON.parse(data.substr(1));
|
||||
if (Config.server.registered && Config.server.id !== 'showdown' && Config.server.id !== 'smogtours') {
|
||||
var $link = $('<link rel="stylesheet" ' +
|
||||
'href="//play.pokemonshowdown.com/customcss.php?server=' +
|
||||
|
|
@ -349,10 +357,10 @@ Storage.onMessage = function ($e) {
|
|||
}
|
||||
break;
|
||||
case 'p':
|
||||
var newData = $.parseJSON(data.substr(1));
|
||||
var newData = JSON.parse(data.substr(1));
|
||||
if (newData) Storage.prefs.data = newData;
|
||||
Storage.prefs.save = function () {
|
||||
var prefData = $.toJSON(this.data);
|
||||
var prefData = JSON.stringify(this.data);
|
||||
Storage.postCrossOriginMessage('P' + prefData);
|
||||
|
||||
// in Safari, cross-origin local storage is apparently treated as session
|
||||
|
|
|
|||
|
|
@ -635,14 +635,6 @@ const Tools = {
|
|||
};
|
||||
})(),
|
||||
|
||||
safeJSON(callback: (safeData: any) => void) {
|
||||
return function (data: string) {
|
||||
if (data.length < 1) return;
|
||||
if (data[0] == ']') data = data.substr(1);
|
||||
return callback($.parseJSON(data));
|
||||
};
|
||||
},
|
||||
|
||||
prefs(prop: string, value?: any, save?: boolean) {
|
||||
// @ts-ignore
|
||||
if (window.Storage && Storage.prefs) return Storage.prefs(prop, value, save);
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@
|
|||
<script src="js/lib/jquery-2.1.4.min.js"></script>
|
||||
<script src="js/lib/jquery-cookie.js"></script>
|
||||
<script src="js/lib/autoresize.jquery.min.js"></script>
|
||||
<script src="js/lib/jquery.json-2.3.min.js"></script>
|
||||
<script src="js/lib/soundmanager2-nodebug-jsmin.js"></script>
|
||||
<script>
|
||||
soundManager.setup({url: 'swf/'});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user