Created
August 6, 2014 12:47
-
-
Save KeithP/300bdd9de2237ea0fbf9 to your computer and use it in GitHub Desktop.
jQuery CoffeeScript for shift + click to select multiple checkboxes
This file contains 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
lastSelected = null | |
checkboxHead = $( "thead :checkbox" ) | |
checkboxes = $( "tbody :checkbox" ) | |
checkboxHead.click (e) -> | |
isChecked = this.checked | |
checkboxes.each -> | |
$(this).prop( "checked", isChecked ) | |
checkboxes.click (e) -> | |
thisSelected = checkboxes.index( this ) | |
isChecked = this.checked | |
if e.shiftKey && thisSelected != lastSelected | |
checkboxes.slice( Math.min( lastSelected, thisSelected ), Math.max( lastSelected, thisSelected ) + 1).each -> | |
$(this).prop( "checked", isChecked ) | |
lastSelected = thisSelected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment