commit 454f575ca9c4e2da5ba8abdb18330da62a35e2d0 Author: Kiphaas7 Date: Tue Sep 4 20:04:27 2012 +0800 typos, qsa diff --git a/core/misc/tableselect.js b/core/misc/tableselect.js index 547bc6f..a718d79 100644 --- a/core/misc/tableselect.js +++ b/core/misc/tableselect.js @@ -20,13 +20,8 @@ function tableSelectInitHandler (context) { var $table = $header.closest('table'); // Do nothing if there are no rows with checkboxes in the table. - var $input = $table.find('td input'); - for (var i = 0, il = $input.length; i < il; i++) { - if ($input[i].type !== 'checkbox') { - continue; - } - - $table.once('table-select', function () { + if ($table.find('td input[type=checkbox]').length) { + $table.once('table-select', function() { TableSelect.tables.push(new TableSelect($table, $header)); }); } @@ -48,11 +43,10 @@ function tableSelectRemoveHander (context) { $table = tables[i].$table; // Unbind all events which are not directly bound to the 'select all' // checkbox. - $table.off('.TableSelect'); - $table.parent().off('.TableSelect'); + $table.off('.tableSelect').parent().off('.tableSelect'); - // Remove the 'select all' checkbox. This will also remove any events - // which are directly bound to the 'select all' checkbox. + // Remove the 'select all' checkbox. This will also remove events which + // are directly bound to the 'select all' checkbox. $selectAll.remove(); // Save the cache entry index for removal. @@ -72,7 +66,7 @@ function tableSelectRemoveHander (context) { $table.removeOnce('table-select'); // Trigger an event letting other scripts know TableSelect was removed. - $table.trigger('TableSelectRemoved', tables[i]); + $table.trigger('tableSelectRemoved', tables[i]); // Remove the entry from cache. TableSelect.tables.splice(index, 1); @@ -137,14 +131,10 @@ $.extend(TableSelect.prototype, { createSelectAll: function () { // Store the checkboxes, initial state and their parent rows. - var $checkboxes = this.$table.find('td input'); + var $checkboxes = this.$table.find('td input[type=checkbox]'); for (var i = 0, il = $checkboxes.length; i < il; i++) { - if ($checkboxes[i].type !== 'checkbox') { - continue; - } - // Reference to checkbox DOM node. - this.checkboxes.push($checkboxes[i]); + this.checkboxes[i] = $checkboxes[i]; // Only count enabled checkboxes. if (!$checkboxes[i].disabled) { @@ -163,7 +153,7 @@ $.extend(TableSelect.prototype, { // Create the 'select all' checkbox. this.$selectAll = $(''); - this.$selectAll.on('click.TableSelect', {TableSelect: this}, this.toggleSelectAll); + this.$selectAll.on('click.tableSelect', {TableSelect: this}, this.toggleSelectAll); // Update the title and selected state of the 'select all' checkbox. this.updateSelectAll(); @@ -173,17 +163,17 @@ $.extend(TableSelect.prototype, { // Listen for the creation of sticky tables. Do this on the direct parent of // the table, to minimise the actual execution of the following function. - this.$table.parent().on('stickyTableCreated.TableSelect', {TableSelect: this}, this.stickyTableCreated); + this.$table.parent().on('stickyTableCreated.tableSelect', {TableSelect: this}, this.stickyTableCreated); - // Look for a sticky table header. This prevents a bug where tableselect and - // not tableheader would go through a detach/attach cycle. + // Look for a sticky table header. This prevents a bug where TableSelect and + // not TableHeader would go through a detach/attach cycle. this.adaptToSticky(this.$table.prev('table.sticky-header')); // Keep track of the checkboxes state. - this.$table.on('click.TableSelect', 'td input', {TableSelect: this}, this.toggleCheckbox); + this.$table.on('click.tableSelect', 'td input[type=checkbox]', {TableSelect: this}, this.toggleCheckbox); // Let other scripts know a 'select all' checkbox was created. - this.$table.trigger('TableSelectCreated', this); + this.$table.trigger('tableSelectCreated', this); }, stickyTableCreated: function (e, tableHeader) { @@ -196,21 +186,12 @@ $.extend(TableSelect.prototype, { // If there is a sticky table header attached to the current table, add the // sticky table 'select all' checkbox to the cached 'select all' selector. - if ($suspectSticky.length && $suspectSticky[0] === $triggerSticky[0]) { + if ($suspectSticky.length && $triggerSticky.length && $suspectSticky[0] === $triggerSticky[0]) { var $stickyHeader = $suspectSticky.find('th.select-all'); + var $stickyCheckbox = $stickyHeader.find('input[type=checkbox]'); if ($stickyHeader.length) { - var $stickyInput = $stickyHeader.find('input'); - var $stickyCheckbox = null; - - for (var i = 0, il = $stickyInput.length; i < il; i++) { - if ($stickyInput[i].type === 'checkbox') { - $stickyCheckbox = $($stickyInput[i]); - break; - } - } - - if ($stickyCheckbox === null) { + if (!$stickyCheckbox.length) { // Re-add the 'select all' checkbox if it was removed. $stickyCheckbox = this.$selectAll.clone(true, true); $stickyHeader.append($stickyCheckbox); @@ -254,10 +235,6 @@ $.extend(TableSelect.prototype, { }, toggleCheckbox: function (e) { - if (this.type !== 'checkbox') { - return; - } - var self = e.data.TableSelect; var currentIndex = $(self.checkboxes).index(this); var lastIndex = self.lastIndex;