-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl-query-helper.min.js
16 lines (16 loc) · 1.24 KB
/
url-query-helper.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
* UrlQueryHelper JavaScript Library v1.0
* https://github.com/toddw/url-query-helper
*
* Requires Underscore.js
* http://underscorejs.org/
*
* Copyright 2013 Todd Williams
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
* Date: 2013-10-22
*/
UrlQueryHelper=function(a,b){this.init&&this.init(a,b)};
UrlQueryHelper.prototype={init:function(a,b){var c=this;c.originalUrl=a;c.updateParams=b;c.params={};1<c.originalUrl.split("?").length&&(originalParamsArray=c.originalUrl.split("?")[1].split("&"),_.each(originalParamsArray,function(a){a=a.split("=");c.params[a[0]]=decodeURI(a[1])}));b&&c.setParams(b);return c},getUrl:function(){return 0<_.size(this.params)?this.originalUrl.split("?")[0]+"?"+_.map(this.params,function(a,b){return b+"="+encodeURI(a)}).join("&"):this.originalUrl.split("?")[0]},getParams:function(){return this.params},
getParam:function(a){return this.params[a]},setParam:function(a,b){this.params[a]=b;return this},setParams:function(a){var b=this;_.each(a,function(a,d){b.setParam(d,a)});return b},removeParam:function(a){this.params=_.omit(this.params,a);return this},removeParams:function(){var a=this;_.each(arguments,function(b){a.removeParam(b)});return a},toString:function(){return this.getUrl()}};