Cache jQuery object to avoid unneeded DOM traversal

This commit is contained in:
Marc Delisle
2011-03-01 08:08:40 -05:00
parent 0d77b5084c
commit 3400dddadd

View File

@@ -85,20 +85,20 @@ function appendNewUser(new_user_string, new_user_initial, new_user_initial_strin
//Append the newly retrived user to the table now
//Calculate the index for the new row
var curr_last_row = $("#usersForm").find('tbody').find('tr:last');
var curr_first_row = $("#usersForm").find('tbody').find('tr:first');
var first_row_initial = $(curr_first_row).find('label').html().substr(0, 1).toUpperCase();
var curr_shown_initial = $(curr_last_row).find('label').html().substr(0, 1).toUpperCase();
var curr_last_row_index_string = $(curr_last_row).find('input:checkbox').attr('id').match(/\d+/)[0];
var $curr_last_row = $("#usersForm").find('tbody').find('tr:last');
var $curr_first_row = $("#usersForm").find('tbody').find('tr:first');
var first_row_initial = $curr_first_row.find('label').html().substr(0, 1).toUpperCase();
var curr_shown_initial = $curr_last_row.find('label').html().substr(0, 1).toUpperCase();
var curr_last_row_index_string = $curr_last_row.find('input:checkbox').attr('id').match(/\d+/)[0];
var curr_last_row_index = parseFloat(curr_last_row_index_string);
var new_last_row_index = curr_last_row_index + 1;
var new_last_row_id = 'checkbox_sel_users_' + new_last_row_index;
var is_show_all = (first_row_initial != curr_shown_initial)?true:false;
var is_show_all = (first_row_initial != curr_shown_initial) ? true : false;
//Append to the table and set the id/names correctly
if((curr_shown_initial == new_user_initial) || is_show_all) {
$(new_user_string)
.insertAfter($(curr_last_row))
.insertAfter($curr_last_row)
.find('input:checkbox')
.attr('id', new_last_row_id)
.val(function() {