Index: misc/tabledrag.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/tabledrag.js,v
retrieving revision 1.31
diff -u -p -r1.31 tabledrag.js
--- misc/tabledrag.js 20 Sep 2009 19:14:40 -0000 1.31
+++ misc/tabledrag.js 23 Sep 2009 20:03:10 -0000
@@ -86,6 +86,11 @@ Drupal.tableDrag = function (table, tabl
// Hide columns containing affected form elements.
this.hideColumns();
+ // Add a link after the table to show/hide this column
+ var showhide = '' + Drupal.t('Show/hide weight fields') +'
';
+ $(this.table).before(showhide);
+ $('a.showhide').click(function () { self.showHideColumns(self); return false; });
+
// Add mouse bindings to the document. The self variable is passed along
// as event handlers do not have direct access to the tableDrag object.
$(document).bind('mousemove', function (event) { return self.dragRow(event, self); });
@@ -109,7 +114,7 @@ Drupal.tableDrag.prototype.hideColumns =
}
// Hide the column containing this field.
- if (hidden && cell[0] && cell.css('display') != 'none') {
+ if (hidden && cell[0]) {
// 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.
var columnIndex = $('> td', cell.parent()).index(cell.get(0)) + 1;
@@ -129,20 +134,45 @@ Drupal.tableDrag.prototype.hideColumns =
cell = row.children(':nth-child(' + index + ')');
if (cell[0].colSpan > 1) {
// If this cell has a colspan, simply reduce it.
- cell[0].colSpan = cell[0].colSpan - 1;
+ cell[0].addClass('tabledrag-reduced-colspan').colSpan = cell[0].colSpan - 1;
}
else {
// Hide table body cells, but remove table header cells entirely
// (Safari doesn't hide properly).
- parentTag == 'thead' ? cell.remove() : cell.css('display', 'none');
+ parentTag == cell.css('display', 'none').addClass('tabledrag-display-none');
}
}
});
}
+
}
};
/**
+ * Un-hide the columns containing form elements according to the settings for
+ * this tableDrag instance. Undo hideColumns().
+ */
+Drupal.tableDrag.prototype.unHideColumns = function () {
+ // Add colspan back where it was reduced
+ $('.tabledrag-reduced-colspan').each( function() { this.colSpan = this.colSpan + 1; } );
+ // Set display block where it was display:none
+ $('.tabledrag-display-none').css('display', 'block');
+}
+
+/**
+ * Show or hide the columns by calling unHideColumns() or hideColumns().
+ */
+Drupal.tableDrag.prototype.showHideColumns = function (self) {
+ if (self.unHiddenColumns) {
+ self.hideColumns()
+ self.unHiddenColumns = false;
+ } else {
+ self.unHideColumns();
+ self.unHiddenColumns = true;
+ }
+}
+
+/**
* Find the target used within a particular row and group.
*/
Drupal.tableDrag.prototype.rowSettings = function (group, row) {