Guest User

Untitled

a guest
Feb 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. # Url search params parser jQuery plugin.
  2. # Usage:
  3. # Get a param
  4. # $.QueryString.param
  5. # - or -
  6. # $.QueryString["param"]
  7. # This outputs something like...
  8. # "val"
  9. #
  10. # Get all params as object
  11. # $.QueryString
  12. # This outputs something like...
  13. # Object { param: "val", param2: "val" }
  14. #
  15. # Set a param (only in the $.QueryString object, doesn't affect the browser's querystring)
  16. # $.QueryString.param = "newvalue"
  17. # This doesn't output anything, it just updates the $.QueryString object
  18. #
  19. # Convert object into string suitable for url a querystring (Requires jQuery)
  20. # $.param($.QueryString)
  21. # This outputs something like...
  22. # "param=newvalue&param2=val"
  23. #
  24. # Update the url/querystring in the browser's location bar with the $.QueryString object
  25. # history.replaceState({}, '', "?" + $.param($.QueryString))
  26. # - or -
  27. # history.pushState({}, '', "?" + $.param($.QueryString))
  28. (($) ->
  29. $.QueryString = ((paramsArray) ->
  30. params = {}
  31.  
  32. for p in paramsArray
  33. param = p.split('=', 2)
  34.  
  35. continue if param.length != 2
  36.  
  37. params[param[0]] = decodeURIComponent(param[1].replace(/\+/g, " "))
  38.  
  39. return params
  40. )(window.location.search.substr(1).split('&'))
  41. )(jQuery)
Add Comment
Please, Sign In to add comment