OpenLayers OpenLayers

Changeset 1013

Show
Ignore:
Timestamp:
07/26/06 11:52:33 (2 years ago)
Author:
euzuro
Message:

removing JSON handling code from Ajax.js. It is not currently needed in this library.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Ajax.js

    r991 r1013  
    107107    return ajaxResponse; 
    108108}; 
    109  
    110 /** Adds a new script element to the head of the current document,  
    111  *   whose src is set to the url passed-in. 
    112  *  
    113  * @param {String} url 
    114  */ 
    115 OpenLayers.addScript = function(url) { 
    116     var head = document.getElementsByTagName("HEAD")[0]; 
    117     var scriptElem = document.createElement("script"); 
    118     scriptElem.src = url; 
    119     head.appendChild(scriptElem); 
    120 }; 
    121  
    122  
    123 (function () { 
    124     var m = { 
    125             '\b': '\\b', 
    126             '\t': '\\t', 
    127             '\n': '\\n', 
    128             '\f': '\\f', 
    129             '\r': '\\r', 
    130             '"' : '\\"', 
    131             '\\': '\\\\' 
    132         }, 
    133         s = { 
    134             array: function (x) { 
    135                 var a = ['['], b, f, i, l = x.length, v; 
    136                 for (i = 0; i < l; i += 1) { 
    137                     v = x[i]; 
    138                     f = s[typeof v]; 
    139                     if (f) { 
    140                         v = f(v); 
    141                         if (typeof v == 'string') { 
    142                             if (b) { 
    143                                 a[a.length] = ','; 
    144                             } 
    145                             a[a.length] = v; 
    146                             b = true; 
    147                         } 
    148                     } 
    149                 } 
    150                 a[a.length] = ']'; 
    151                 return a.join(''); 
    152             }, 
    153             'boolean': function (x) { 
    154                 return String(x); 
    155             }, 
    156             'null': function (x) { 
    157                 return "null"; 
    158             }, 
    159             number: function (x) { 
    160                 return isFinite(x) ? String(x) : 'null'; 
    161             }, 
    162             object: function (x) { 
    163                 if (x) { 
    164                     if (x instanceof Array) { 
    165                         return s.array(x); 
    166                     } 
    167                     var a = ['{'], b, f, i, v; 
    168                     for (i in x) { 
    169                         v = x[i]; 
    170                         f = s[typeof v]; 
    171                         if (f) { 
    172                             v = f(v); 
    173                             if (typeof v == 'string') { 
    174                                 if (b) { 
    175                                     a[a.length] = ','; 
    176                                 } 
    177                                 a.push(s.string(i), ':', v); 
    178                                 b = true; 
    179                             } 
    180                         } 
    181                     } 
    182                     a[a.length] = '}'; 
    183                     return a.join(''); 
    184                 } 
    185                 return 'null'; 
    186             }, 
    187             string: function (x) { 
    188                 if (/["\\\x00-\x1f]/.test(x)) { 
    189                     x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) { 
    190                         var c = m[b]; 
    191                         if (c) { 
    192                             return c; 
    193                         } 
    194                         c = b.charCodeAt(); 
    195                         return '\\u00' + 
    196                             Math.floor(c / 16).toString(16) + 
    197                             (c % 16).toString(16); 
    198                     }); 
    199                 } 
    200                 return '"' + x + '"'; 
    201             } 
    202         }; 
    203  
    204 /*    Object.prototype.toJSONString = function () { 
    205         return s.object(this); 
    206     }; 
    207  
    208     Array.prototype.toJSONString = function () { 
    209         return s.array(this); 
    210     }; 
    211 */ 
    212 })(); 
    213  
    214 String.prototype.parseJSON = function () { 
    215     try { 
    216         return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test( 
    217                 this.replace(/"(\\.|[^"\\])*"/g, ''))) && 
    218             eval('(' + this + ')'); 
    219     } catch (e) { 
    220         return false; 
    221     } 
    222 };