Skip to content

Instantly share code, notes, and snippets.

@nickjacob
Last active December 14, 2015 06:39
Show Gist options
  • Save nickjacob/5044374 to your computer and use it in GitHub Desktop.
Save nickjacob/5044374 to your computer and use it in GitHub Desktop.
just an idea I wanted to play with; for a searching app, shouldn't the user be able to refresh and get the same parameters in the field/query?
inputRe = /input|select|textarea/i # some browsers do uppercase tagNames; also faster than 3 strcmp
cache = {}
elByName = (el) ->
cache[el.name] ?= document.getElementsByName el.name
document.addEventListener 'load', (e) ->
document.addEventListener 'change', (e) ->
target = e.target
if inputRe.test target.tagName
window.location.search ||= '?'
window.location.search += "#{ target.name }=#{ [ t.value for t in elByName target.name ].join ',' ]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment