-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.parseQuery.js
23 lines (22 loc) · 1.06 KB
/
jquery.parseQuery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* A simple querystring parser.
* Example usage: var q = $.parseQuery(); q.fooreturns "bar" if query contains "?foo=bar"; multiple values are added to an array.
* Values are unescaped by default and plus signs replaced with spaces, or an alternate processing function can be passed in the params object .
* http://actingthemaggot.com/jquery
*
* Copyright (c) 2008 Michael Manning (http://actingthemaggot.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* ^(\?|#)?(.*)$
*
**/
jQuery.parseQuery = function(qs,options) {
var q = (typeof qs === 'string'?qs:window.location.search), o = {'f':function(v){return unescape(v).replace(/\+/g,' ');}}, options = (typeof qs === 'object' && typeof options === 'undefined')?qs:options, o = jQuery.extend({}, o, options), params = {};
jQuery.each(q.match(/^\??(.*)$/)[1].split('&'),function(i,p){
p = p.split('=');
p[1] = o.f(p[1]);
params[p[0]] = params[p[0]]?((params[p[0]] instanceof Array)?(params[p[0]].push(p[1]),params[p[0]]):[params[p[0]],p[1]]):p[1];
});
return params;
}