-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgurli.js
58 lines (45 loc) · 1.47 KB
/
gurli.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Generated by CoffeeScript 1.4.0
(function() {
var Gurli;
Gurli = (function() {
function Gurli() {
var pairArray, pairIndex, paramsArray;
this.baseURL = window.location.href.split("?")[0];
paramsArray = window.location.href.split("?")[1];
paramsArray = paramsArray ? paramsArray.split("&") : [];
this.params = {};
for (pairIndex in paramsArray) {
pairArray = paramsArray[pairIndex].split("=");
this.params[decodeURIComponent(pairArray[0])] = decodeURIComponent(pairArray[1]);
}
}
Gurli.prototype.setParam = function(name, value) {
return this.params[name] = value;
};
Gurli.prototype.getParam = function(name) {
return this.params[name];
};
Gurli.prototype.removeParam = function(name) {
return delete this.params[name];
};
Gurli.prototype.clearParams = function() {
this.params = [];
};
Gurli.prototype.setBaseURL = function(newURL) {
return this.baseURL = encodeURI(newURL);
};
Gurli.prototype.toURL = function() {
var property, urlString;
urlString = this.baseURL + "?";
for (property in this.params) {
urlString = urlString + encodeURIComponent(property) + "=" + encodeURIComponent(this.params[property]) + "&";
}
return urlString.slice(0, -1);
};
Gurli.prototype.goto = function() {
return window.location = this.toURL();
};
return Gurli;
})();
window.Gurli = Gurli;
}).call(this);