Skip to content

Instantly share code, notes, and snippets.

@rev22
Created October 25, 2014 17:02
Show Gist options
  • Save rev22/2d26deb56f944527da0f to your computer and use it in GitHub Desktop.
Save rev22/2d26deb56f944527da0f to your computer and use it in GitHub Desktop.
multiple selection without CTRL
ignoreEvent = (event)->
event.preventDefault()
event.stopPropagation()
true
$('select[multiple]').each ->
select = $ @
values = {}
$('option',select)
.each (i, option)->
values[option.value] = !!option.selected
.on 'mousedown', ignoreEvent
.on 'mouseup', ignoreEvent
.click (event)->
ignoreEvent(event)
values[@value] = !values[@value];
refreshValues = ->
$('option',select).each (i, option)->
option.selected = if values[option.value] ? "" then "1" else ""
refreshValues()
setTimeout refreshValues, 0
setTimeout refreshValues, 20
setTimeout refreshValues, 100
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment