Last active
November 23, 2016 04:47
-
-
Save Uysim/d9b63876812b8b29a3cb8f3413519237 to your computer and use it in GitHub Desktop.
this script use for custom url params and redirect it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// new ParamsHandler({ location_id: object.id, page: 1 }).redirect(); | |
window.ParamsHandler = (function() { | |
function ParamsHandler(params) { | |
this.params = params; | |
this.kvp = document.location.search.substr(1).split('&'); | |
} | |
ParamsHandler.prototype.redirect = function() { | |
this._mapParams(); | |
return document.location.search = this.kvp.join('&'); | |
}; | |
ParamsHandler.prototype._mapParams = function() { | |
var key, ref, results, value; | |
ref = this.params; | |
results = []; | |
for (key in ref) { | |
value = ref[key]; | |
results.push(this._insertParam(key, value)); | |
} | |
return results; | |
}; | |
ParamsHandler.prototype._insertParam = function(key, value) { | |
var i, x; | |
console.log(key); | |
key = encodeURI(key); | |
value = encodeURI(value); | |
i = this.kvp.length; | |
x = void 0; | |
while (i--) { | |
x = this.kvp[i].split('='); | |
if (x[0] === key) { | |
x[1] = value; | |
this.kvp[i] = x.join('='); | |
break; | |
} | |
} | |
if (i < 0) { | |
return this.kvp.push(key + "=" + value); | |
} | |
}; | |
return ParamsHandler; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment