Skip to content

Commit

Permalink
expanded documentation with more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlac committed Mar 12, 2013
1 parent 412d2d9 commit 7893d59
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,49 @@ jquery-drag-check

jQuery plugin for checking multiple checkboxes by click-dragging over them.

## Initialize with default behaviour:
$(':checkbox').dragCheck();

## If you want to avoid triggering the 'change' event, and add your own code instead:
$(':checkbox').dragCheck({
onChange: function(event) {
$(this).closest('tr').toggleClass('highlighted', this.value);
}
});

## If you want to wait for the user to finish before doing something (e.g. a heavy UI update/selector)
$(':checkbox').dragCheck({
deferChangeTrigger: true,
onDragEnd: function() {
$('span.checkbox-count').text($(':checkbox:checked').size());
}
});

## Sometimes, it's ok to update if user manually selects one checkbox at a time, but drag-checking should be handled in 1 swoop.
var triggerChange = function() {
$(this).closest('tr').toggleClass('highlighted', this.value);
}
var heavyUpdate = function() {
// For demonstration purpose this operation relies on UI being up-to-date (triggerChange has been called with all checked boxes)
$('span.checkbox-count').text($('tr.highlighted').size());
}

$(':checkbox').change(function() {
triggerChange.call(this);
heavyUpdate();
});

$(':checkbox').dragCheck({
deferChangeTrigger: true,
onDragEnd: function(items) {
// Call change event to make sure UI reflects selection
for(var i in items) {
triggerChange.call(items[i]);
};

heavyUpdate();
}
});

See a demo here:
http://www.seph.dk/jquery-dragcheck/demo.html

0 comments on commit 7893d59

Please sign in to comment.