Index: misc/tabledrag.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/tabledrag.js,v
retrieving revision 1.32
diff -u -p -r1.32 tabledrag.js
--- misc/tabledrag.js 3 Nov 2009 05:34:37 -0000 1.32
+++ misc/tabledrag.js 27 Nov 2009 17:51:58 -0000
@@ -83,8 +83,16 @@ Drupal.tableDrag = function (table, tabl
// Match immediate children of the parent element to allow nesting.
$('> tr.draggable, > tbody > tr.draggable', table).each(function() { self.makeDraggable(this); });
- // Hide columns containing affected form elements.
- this.hideColumns();
+ // Check initial status to see if the columns containing affected form
+ // elements should be hidden.
+ self.showHideColumns();
+
+ // 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.setShowHideCookie(self); return false; });
+
+ // self.showHideColumns();
// Add mouse bindings to the document. The self variable is passed along
// as event handlers do not have direct access to the tableDrag object.
@@ -109,7 +117,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 +137,86 @@ 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');
+}
+
+/**
+ * Retrieve last saved cookie settings and set up the initial tableDrag state.
+ * Show or hide the columns by calling unHideColumns() or hideColumns().
+ */
+Drupal.tableDrag.prototype.showHideColumns = function (self) {
+ // Retrieve the tableDrag status from a stored cookie.
+ var exposed = $.cookie('Drupal.tableDrag.prototype.default');
+
+ // Enable/Disable tableDrag based on the cookie value.
+ if (exposed == 1) {
+ this.unHideColumns();
+ }
+ else {
+ this.hideColumns();
+ }
+
+}
+
+/**
+ * Change Cookies - Run when Show/Hide weight fields link clicked
+ */
+ Drupal.tableDrag.prototype.setShowHideCookie = function (self) {
+ // Retrieve the tableDrag status from a stored cookie.
+ var exposed = $.cookie('Drupal.tableDrag.prototype.default');
+
+ // Enable/Disable tableDrag based on the cookie value.
+ if (exposed == 1) {
+ $.cookie(
+ 'Drupal.tableDrag.prototype.default',
+ 0,
+ {
+ path: Drupal.settings.basePath,
+ // The cookie should "never" expire.
+ expires: 36500
+ }
+ );
+ this.unHideColumns();
+ }
+ else {
+ $.cookie(
+ 'Drupal.tableDrag.prototype.default',
+ 1,
+ {
+ path: Drupal.settings.basePath,
+ // The cookie should "never" expire.
+ expires: 36500
+ }
+ );
+ this.hideColumns();
+ }
+
+ }
+
+
+/**
* Find the target used within a particular row and group.
*/
Drupal.tableDrag.prototype.rowSettings = function (group, row) {