1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
-
- (function ($) {
- $.deparam = function (params, coerce) {
- var obj = {},
- coerce_types = { 'true': !0, 'false': !1, 'null': null };
-
-
- $.each(params.replace(/\+/g, ' ').split('&'), function (j,v) {
- var param = v.split('='),
- key = decodeURIComponent(param[0]),
- val,
- cur = obj,
- i = 0,
-
-
-
- keys = key.split(']['),
- keys_last = keys.length - 1;
-
-
-
- if (/\[/.test(keys[0]) && /\]$/.test(keys[keys_last])) {
-
- keys[keys_last] = keys[keys_last].replace(/\]$/, '');
-
-
-
- keys = keys.shift().split('[').concat(keys);
-
- keys_last = keys.length - 1;
- } else {
-
- keys_last = 0;
- }
-
-
- if (param.length === 2) {
- val = decodeURIComponent(param[1]);
-
-
- if (coerce) {
- val = val && !isNaN(val) ? +val
- : val === 'undefined' ? undefined
- : coerce_types[val] !== undefined ? coerce_types[val]
- : val;
- }
-
- if ( keys_last ) {
-
-
-
-
-
-
-
-
-
- for (; i <= keys_last; i++) {
- key = keys[i] === '' ? cur.length : keys[i];
- cur = cur[key] = i < keys_last
- ? cur[key] || (keys[i+1] && isNaN(keys[i+1]) ? {} : [])
- : val;
- }
-
- } else {
-
-
-
- if ($.isArray(obj[key])) {
-
- obj[key].push( val );
-
- } else if (obj[key] !== undefined) {
-
-
- obj[key] = [obj[key], val];
-
- } else {
-
- obj[key] = val;
- }
- }
-
- } else if (key) {
-
- obj[key] = coerce
- ? undefined
- : '';
- }
- });
-
- return obj;
- };
- })(jQuery);
|