Created
October 25, 2014 17:02
-
-
Save rev22/2d26deb56f944527da0f to your computer and use it in GitHub Desktop.
multiple selection without CTRL
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
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