Created
October 25, 2015 20:02
-
-
Save gbuesing/783d23441af7421af67b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
addParams = (path, params) -> | |
query = objToQuery(params) | |
joinChar = if /\?/.test(path) then '&' else '?' | |
"#{path}#{joinChar}#{query}" | |
objToQuery = (obj) -> | |
pairs = [] | |
for own key, val of obj | |
if val? and val != '' | |
val = encodeURIComponent(val) | |
pairs.push("#{encodeURIComponent(key)}=#{val}") | |
pairs.join('&') | |
# returns querystring as an object | |
parseParams = -> | |
query = window.location.search.substr(1) | |
out = {} | |
return out unless query != '' | |
for keyval in query.split('&') | |
pair = keyval.split('=') | |
key = decodeURIComponent(pair[0]) | |
val = pair[1] | |
if val? && val != '' | |
out[key] = decodeURIComponent(val) | |
else | |
out[key] = null | |
out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment