Merge pull request #119 from balkansalat/rails3-improve-checkall-performance
Improve performance of *check-all* checkbox
This commit is contained in:
commit
241c5666ec
1 changed files with 9 additions and 6 deletions
|
@ -35,11 +35,14 @@ $(function() {
|
|||
|
||||
// Check/Uncheck all checkboxes for a specific form
|
||||
$('input[data-check-all]').live('click', function() {
|
||||
var status = $(this).is(':checked')
|
||||
$($(this).data('check-all')).find('input[type="checkbox"]').each(function() {
|
||||
$(this).attr('checked', status);
|
||||
highlightRow($(this));
|
||||
});
|
||||
var status = $(this).is(':checked');
|
||||
var context = $(this).data('check-all');
|
||||
var elms = $('input[type="checkbox"]', context);
|
||||
for(i=elms.length-1; i>=0; --i) { // performance can be an issue here, so use native loop
|
||||
var elm = elms[i];
|
||||
elm.checked = status;
|
||||
highlightRow($(elm));
|
||||
}
|
||||
});
|
||||
|
||||
// Submit form when changing a select menu.
|
||||
|
@ -102,7 +105,7 @@ $(function() {
|
|||
|
||||
// gives the row an yellow background
|
||||
function highlightRow(checkbox) {
|
||||
var row = checkbox.parents('tr');
|
||||
var row = checkbox.closest('tr');
|
||||
if (checkbox.is(':checked')) {
|
||||
row.addClass('selected');
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue