Improve performance of data-check-all

This commit is contained in:
Julius 2013-06-06 17:06:05 +02:00
parent 53518039f1
commit 0d3c23f814

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.
@ -101,8 +104,8 @@ $(function() {
// gives the row an yellow background // gives the row an yellow background
function highlightRow(checkbox) { function highlightRow(checkbox, status) {
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 {