-
Notifications
You must be signed in to change notification settings - Fork 0
/
getUrlVars_.js
35 lines (30 loc) · 1.03 KB
/
getUrlVars_.js
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
var GetUrlVars = {};
(function(){
GetUrlVars = function(){
if( !(this instanceof GetUrlVars))
return new GetUrlVars();
this.response = { found: false, queryParams: {}, match: {} };
this.queryScope = window.location;
if(this.queryScope.search.length > 0){
var urlVarString = this.queryScope.search.replace("?", "");
var urlVarStringArr = urlVarString.split("&");
for(var i = 0; i < urlVarStringArr.length; i++){
var currVarArr = urlVarStringArr[i].split("=");
if(currVarArr[0].length > 0 && currVarArr[1]){
this[currVarArr[0]] = currVarArr[1];
this.response.queryParams[currVarArr[0]] = currVarArr[1];
}
}
}
};
GetUrlVars.prototype = {
isAvailable: function( queryParam, type ){
if(typeof(this.response.queryParams[queryParam]) === type && this.response.queryParams[queryParam].length > 0){
this.response.found = true;
this.response.match = this.response.queryParams[queryParam];
}
return this.response;
}
};
//GetUrlVars().isAvailable('q', 'string');
})();