Skip to content

Instantly share code, notes, and snippets.

@rodolfofadino
Created July 26, 2012 13:39
Show Gist options
  • Save rodolfofadino/3182076 to your computer and use it in GitHub Desktop.
Save rodolfofadino/3182076 to your computer and use it in GitHub Desktop.
CheckBox Range Selection
(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