Created
January 20, 2011 10:03
-
-
Save greystate/787685 to your computer and use it in GitHub Desktop.
A couple of helpers...
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
function filterBy(selector) { | |
var c = selector.value, loc = document.location, q = loc.search; | |
q = addOrReplaceQueryStringParam(q, "category", c); | |
document.location = loc.pathname + q; | |
} | |
function gotoCategory(selector) { | |
var c = selector.value; | |
document.location = "/produkter?category=" + encodeURIComponent(c); | |
} | |
function addOrReplaceQueryStringParam(qs, name, value) { | |
qs = qs.indexOf("?") == 0 ? qs.substr(1) : qs; | |
var params = qs ? qs.split("&") : [ ]; | |
if (qs.indexOf(name) >= 0) { | |
for (var i = params.length - 1; i >= 0; i--) { | |
if (params[i].indexOf(name) == 0) { | |
params[i] = name + "=" + encodeURIComponent(value); | |
} | |
} | |
} else { | |
params.push(name + "=" + encodeURIComponent(value)); | |
} | |
return "?" + params.join("&"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment