Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Url search params parser jQuery plugin.
- # Usage:
- # Get a param
- # $.QueryString.param
- # - or -
- # $.QueryString["param"]
- # This outputs something like...
- # "val"
- #
- # Get all params as object
- # $.QueryString
- # This outputs something like...
- # Object { param: "val", param2: "val" }
- #
- # Set a param (only in the $.QueryString object, doesn't affect the browser's querystring)
- # $.QueryString.param = "newvalue"
- # This doesn't output anything, it just updates the $.QueryString object
- #
- # Convert object into string suitable for url a querystring (Requires jQuery)
- # $.param($.QueryString)
- # This outputs something like...
- # "param=newvalue¶m2=val"
- #
- # Update the url/querystring in the browser's location bar with the $.QueryString object
- # history.replaceState({}, '', "?" + $.param($.QueryString))
- # - or -
- # history.pushState({}, '', "?" + $.param($.QueryString))
- (($) ->
- $.QueryString = ((paramsArray) ->
- params = {}
- for p in paramsArray
- param = p.split('=', 2)
- continue if param.length != 2
- params[param[0]] = decodeURIComponent(param[1].replace(/\+/g, " "))
- return params
- )(window.location.search.substr(1).split('&'))
- )(jQuery)
Add Comment
Please, Sign In to add comment