-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjquery.getparam.js
More file actions
48 lines (40 loc) · 955 Bytes
/
jquery.getparam.js
File metadata and controls
48 lines (40 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
Author: Matt Bower <matt@webbower.com>
Date: March 2011
*/
;(function($) {
var
_parseParams = function(url) {
if(!url) return {};
var
_params = {},
qStart = url.indexOf('?'),
hStart = url.indexOf('#'),
q = url.substr(qStart + 1),
tmp,
parts,
i
;
if(hStart === -1) hStart = url.length;
// q = qStart < hStart ? url.substring(qStart + 1, hStart) : url.substring(hStart, qStart);
if(q) {
tmp = q.split('&');
i = tmp.length;
while(i--) {
parts = tmp[i].split('=');
// _params[parts[0]] = decodeURIComponent(parts[1]).replace(/\+/g,' ');
_params[parts[0]] = parts[1];
}
}
return _params;
}
;
$.getParam = function(key) {
if(!key || $.type(key) !== 'string') return $._GET;
return $._GET[key] ? $._GET[key] : null;
};
$.parseParams = function(url) {
return _parseParams(url);
};
$.GET = $._GET = $.parseParams(location.href);
})(jQuery);