Merge pull request #119 from balkansalat/rails3-improve-checkall-performance

Improve performance of *check-all* checkbox
This commit is contained in:
Benjamin Meichsner 2013-06-09 09:19:19 -07:00
commit 241c5666ec

View file

@ -35,11 +35,14 @@ $(function() {
// Check/Uncheck all checkboxes for a specific form // Check/Uncheck all checkboxes for a specific form
$('input[data-check-all]').live('click', function() { $('input[data-check-all]').live('click', function() {
var status = $(this).is(':checked') var status = $(this).is(':checked');
$($(this).data('check-all')).find('input[type="checkbox"]').each(function() { var context = $(this).data('check-all');
$(this).attr('checked', status); var elms = $('input[type="checkbox"]', context);
highlightRow($(this)); 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. // Submit form when changing a select menu.
@ -102,7 +105,7 @@ $(function() {
// gives the row an yellow background // gives the row an yellow background
function highlightRow(checkbox) { function highlightRow(checkbox) {
var row = checkbox.parents('tr'); var row = checkbox.closest('tr');
if (checkbox.is(':checked')) { if (checkbox.is(':checked')) {
row.addClass('selected'); row.addClass('selected');
} else { } else {