Created
July 26, 2012 13:39
-
-
Save rodolfofadino/3182076 to your computer and use it in GitHub Desktop.
CheckBox Range Selection
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
(function ($) { | |
$.fn.enableCheckboxRangeSelection = function () { | |
var lastCheckbox = null; | |
var $spec = this; | |
$spec.unbind("click.checkboxrange"); | |
$spec.bind("click.checkboxrange", function (e) { | |
if (lastCheckbox != null && (e.shiftKey || e.metaKey)) { | |
$spec.slice( | |
Math.min($spec.index(lastCheckbox), $spec.index(e.target)), | |
Math.max($spec.index(lastCheckbox), $spec.index(e.target)) + 1 | |
).attr({ checked: e.target.checked ? "checked" : "" }); | |
} | |
lastCheckbox = e.target; | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment