diff --git a/core/misc/tabledrag.js b/core/misc/tabledrag.js index c3a0f5a..52ad4dd 100644 --- a/core/misc/tabledrag.js +++ b/core/misc/tabledrag.js @@ -266,30 +266,36 @@ */ Drupal.tableDrag.prototype.initColumns = function () { var $table = this.$table; - var hidden; - var cell; + var hasHiddenColumn; + var $cells; var columnIndex; + + function isHiddenColumn(element, index, array) { + if (element.hidden) { + var td = 'td.' + element.target; + var th = 'th.' + element.target; + $cells = $table.find(td, th); + if ($cells.length) { + return true; + } + } + } + for (var group in this.tableSettings) { if (this.tableSettings.hasOwnProperty(group)) { - // Find the first field in this group. - for (var d in this.tableSettings[group]) { - if (this.tableSettings[group].hasOwnProperty(d)) { - var field = $table.find('.' + this.tableSettings[group][d].target).eq(0); - if (field.length && this.tableSettings[group][d].hidden) { - hidden = this.tableSettings[group][d].hidden; - cell = field.closest('td'); - break; - } - } - } + // tests whether some element with target class in this group. + hasHiddenColumn = this.tableSettings[group].some(isHiddenColumn); // Mark the column containing this field so it can be hidden. - if (hidden && cell[0]) { + if (hasHiddenColumn) { + // Add 1 to our indexes. The nth-child selector is 1 based, not 0 // based. Match immediate children of the parent element to allow // nesting. - columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1; + columnIndex = $cells.index() + 1; + // Check whether the matching cell is in a row containing colspans. + // If so, adjust columnIndex accordingly. $table.find('> thead > tr, > tbody > tr, > tr').each(this.addColspanClass(columnIndex)); } } @@ -311,15 +317,24 @@ // Get the columnIndex and adjust for any colspans in this row. var $row = $(this); var index = columnIndex; - var cells = $row.children(); + var $cells = $row.children(); var cell; - cells.each(function (n) { + + var origIndex = index; + $cells.each(function (n) { + if (n < origIndex && this.colSpan && this.colSpan > 1) { + index += this.colSpan - 1; + } + }); + + $cells.each(function (n) { if (n < index && this.colSpan && this.colSpan > 1) { index -= this.colSpan - 1; } }); + if (index > 0) { - cell = cells.filter(':nth-child(' + index + ')'); + cell = $cells.filter(':nth-child(' + index + ')'); if (cell[0].colSpan && cell[0].colSpan > 1) { // If this cell has a colspan, mark it so we can reduce the colspan. cell.addClass('tabledrag-has-colspan'); @@ -1341,7 +1356,7 @@ } } - return {'min': minIndent, 'max': maxIndent}; + return {min: minIndent, max: maxIndent}; }; /**