Changeset 12781


Ignore:
Timestamp:
Aug 28, 2011, 2:51:49 PM (10 years ago)
Author:
jordan
Message:

(trunk web) migrate from json.js to json2.js. <http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/>

Location:
trunk/web
Files:
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/index.html

    r12770 r12781  
    2626                <script type="text/javascript" src="./javascript/menu.js"></script>
    2727                <script type="text/javascript" src="./javascript/jquery/jquery.form.min.js"></script>
    28                 <script type="text/javascript" src="./javascript/jquery/json.min.js"></script>
     28                <script type="text/javascript" src="./javascript/jquery/json2.min.js"></script>
    2929                <script type="text/javascript" src="./javascript/common.js"></script>
    3030                <script type="text/javascript" src="./javascript/transmission.remote.js"></script>
  • trunk/web/javascript/jquery/Makefile.am

    r12712 r12781  
    66  jquery.form.min.js \
    77  jquery.transmenu.min.js \
    8   json.min.js
     8  json2.min.js
  • trunk/web/javascript/jquery/json2.js

    r11327 r12781  
    1 alert('IMPORTANT: Remove this line from json2.js before deployment.');
    21/*
    32    http://www.JSON.org/json2.js
    4     2010-08-25
     3    2011-02-23
    54
    65    Public Domain.
     
    148147*/
    149148
    150 /*jslint evil: true, strict: false */
     149/*jslint evil: true, strict: false, regexp: false */
    151150
    152151/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
     
    161160// methods in a closure to avoid creating global variables.
    162161
    163 if (!this.JSON) {
    164     this.JSON = {};
     162var JSON;
     163if (!JSON) {
     164    JSON = {};
    165165}
    166166
    167167(function () {
     168    "use strict";
    168169
    169170    function f(n) {
     
    177178
    178179            return isFinite(this.valueOf()) ?
    179                    this.getUTCFullYear()   + '-' +
    180                  f(this.getUTCMonth() + 1) + '-' +
    181                  f(this.getUTCDate())      + 'T' +
    182                  f(this.getUTCHours())     + ':' +
    183                  f(this.getUTCMinutes())   + ':' +
    184                  f(this.getUTCSeconds())   + 'Z' : null;
     180                this.getUTCFullYear()     + '-' +
     181                f(this.getUTCMonth() + 1) + '-' +
     182                f(this.getUTCDate())      + 'T' +
     183                f(this.getUTCHours())     + ':' +
     184                f(this.getUTCMinutes())   + ':' +
     185                f(this.getUTCSeconds())   + 'Z' : null;
    185186        };
    186187
    187         String.prototype.toJSON =
    188         Number.prototype.toJSON =
    189         Boolean.prototype.toJSON = function (key) {
    190             return this.valueOf();
    191         };
     188        String.prototype.toJSON      =
     189            Number.prototype.toJSON =
     190            Boolean.prototype.toJSON = function (key) {
     191                return this.valueOf();
     192            };
    192193    }
    193194
     
    216217
    217218        escapable.lastIndex = 0;
    218         return escapable.test(string) ?
    219             '"' + string.replace(escapable, function (a) {
    220                 var c = meta[a];
    221                 return typeof c === 'string' ? c :
    222                     '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
    223             }) + '"' :
    224             '"' + string + '"';
     219        return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
     220            var c = meta[a];
     221            return typeof c === 'string' ? c :
     222                '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
     223        }) + '"' : '"' + string + '"';
    225224    }
    226225
     
    305304// brackets.
    306305
    307                 v = partial.length === 0 ? '[]' :
    308                     gap ? '[\n' + gap +
    309                             partial.join(',\n' + gap) + '\n' +
    310                                 mind + ']' :
    311                           '[' + partial.join(',') + ']';
     306                v = partial.length === 0 ? '[]' : gap ?
     307                    '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
     308                    '[' + partial.join(',') + ']';
    312309                gap = mind;
    313310                return v;
     
    319316                length = rep.length;
    320317                for (i = 0; i < length; i += 1) {
    321                     k = rep[i];
    322                     if (typeof k === 'string') {
     318                    if (typeof rep[i] === 'string') {
     319                        k = rep[i];
    323320                        v = str(k, value);
    324321                        if (v) {
     
    332329
    333330                for (k in value) {
    334                     if (Object.hasOwnProperty.call(value, k)) {
     331                    if (Object.prototype.hasOwnProperty.call(value, k)) {
    335332                        v = str(k, value);
    336333                        if (v) {
     
    344341// and wrap them in braces.
    345342
    346             v = partial.length === 0 ? '{}' :
    347                 gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
    348                         mind + '}' : '{' + partial.join(',') + '}';
     343            v = partial.length === 0 ? '{}' : gap ?
     344                '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
     345                '{' + partial.join(',') + '}';
    349346            gap = mind;
    350347            return v;
     
    387384            if (replacer && typeof replacer !== 'function' &&
    388385                    (typeof replacer !== 'object' ||
    389                      typeof replacer.length !== 'number')) {
     386                    typeof replacer.length !== 'number')) {
    390387                throw new Error('JSON.stringify');
    391388            }
     
    417414                if (value && typeof value === 'object') {
    418415                    for (k in value) {
    419                         if (Object.hasOwnProperty.call(value, k)) {
     416                        if (Object.prototype.hasOwnProperty.call(value, k)) {
    420417                            v = walk(value, k);
    421418                            if (v !== undefined) {
     
    458455
    459456            if (/^[\],:{}\s]*$/
    460 .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
    461 .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
    462 .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
     457                    .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
     458                        .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
     459                        .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
    463460
    464461// In the third stage we use the eval function to compile the text into a
  • trunk/web/javascript/jquery/json2.min.js

    r11327 r12781  
    1 if(!this.JSON){this.JSON={}}(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||"null"}v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";gap=mind;return v}if(rep&&typeof rep==="object"){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==="string"){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}v=partial.length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";gap=mind;return v}}if(typeof JSON.stringify!=="function"){JSON.stringify=function(value,replacer,space){var i;gap="";indent="";if(typeof space==="number"){for(i=0;i<space;i+=1){indent+=" "}}else{if(typeof space==="string"){indent=space}}rep=replacer;if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":value})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==="object"){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}}());
     1var JSON;if(!JSON){JSON={}}(function(){function str(a,b){var c,d,e,f,g=gap,h,i=b[a];if(i&&typeof i==="object"&&typeof i.toJSON==="function"){i=i.toJSON(a)}if(typeof rep==="function"){i=rep.call(b,a,i)}switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i){return"null"}gap+=indent;h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c<f;c+=1){h[c]=str(c,i)||"null"}e=h.length===0?"[]":gap?"[\n"+gap+h.join(",\n"+gap)+"\n"+g+"]":"["+h.join(",")+"]";gap=g;return e}if(rep&&typeof rep==="object"){f=rep.length;for(c=0;c<f;c+=1){if(typeof rep[c]==="string"){d=rep[c];e=str(d,i);if(e){h.push(quote(d)+(gap?": ":":")+e)}}}}else{for(d in i){if(Object.prototype.hasOwnProperty.call(i,d)){e=str(d,i);if(e){h.push(quote(d)+(gap?": ":":")+e)}}}}e=h.length===0?"{}":gap?"{\n"+gap+h.join(",\n"+gap)+"\n"+g+"}":"{"+h.join(",")+"}";gap=g;return e}}function quote(a){escapable.lastIndex=0;return escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return typeof b==="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function f(a){return a<10?"0"+a:a}"use strict";if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(a){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(a){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;if(typeof JSON.stringify!=="function"){JSON.stringify=function(a,b,c){var d;gap="";indent="";if(typeof c==="number"){for(d=0;d<c;d+=1){indent+=" "}}else if(typeof c==="string"){indent=c}rep=b;if(b&&typeof b!=="function"&&(typeof b!=="object"||typeof b.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":a})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&typeof e==="object"){for(c in e){if(Object.prototype.hasOwnProperty.call(e,c)){d=walk(e,c);if(d!==undefined){e[c]=d}else{delete e[c]}}}}return reviver.call(a,b,e)}var j;text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}})()
  • trunk/web/javascript/transmission.remote.js

    r12780 r12781  
    108108                        dataType: 'json',
    109109                        cache: false,
    110                         data: $.toJSON(data),
     110                        data: JSON.stringify(data),
    111111                        beforeSend: function(XHR){ remote.appendSessionId(XHR); },
    112112                        error: function(request, error_string, exception){ remote.ajaxError(request, error_string, exception, ajaxSettings); },
Note: See TracChangeset for help on using the changeset viewer.