diff misc/tabledrag.js @ 7:fff6d4c8c043 6.3

Drupal 6.3
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:30:28 +0100
parents c1f4ac30525a
children 589fb7c02327
line wrap: on
line diff
--- a/misc/tabledrag.js	Tue Dec 23 14:30:08 2008 +0100
+++ b/misc/tabledrag.js	Tue Dec 23 14:30:28 2008 +0100
@@ -1,4 +1,4 @@
-// $Id: tabledrag.js,v 1.13.2.1 2008/02/08 18:54:10 goba Exp $
+// $Id: tabledrag.js,v 1.13.2.3 2008/06/12 19:13:25 dries Exp $
 
 /**
  * Drag and drop table rows with field manipulation.
@@ -87,49 +87,53 @@
 
   // 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) { self.dragRow(event, self); return false; });
-  $(document).bind('mouseup', function(event) { self.dropRow(event, self); });
+  $(document).bind('mousemove', function(event) { return self.dragRow(event, self); });
+  $(document).bind('mouseup', function(event) { return self.dropRow(event, self); });
 };
 
 /**
  * Hide the columns containing form elements according to the settings for
  * this tableDrag instance.
  */
-Drupal.tableDrag.prototype.hideColumns = function() {
+Drupal.tableDrag.prototype.hideColumns = function(){
   for (var group in this.tableSettings) {
     // Find the first field in this group.
     for (var d in this.tableSettings[group]) {
-      if ($('.' + this.tableSettings[group][d]['target'], this.table).size()) {
+      var field = $('.' + this.tableSettings[group][d]['target'] + ':first', this.table);
+      if (field.size() && this.tableSettings[group][d]['hidden']) {
         var hidden = this.tableSettings[group][d]['hidden'];
-        var field = $('.' + this.tableSettings[group][d]['target'] + ':first', this.table);
-        var cell = field.parents('td:first, th:first');
+        var cell = field.parents('td:first');
         break;
       }
     }
+
     // Hide the column containing this field.
     if (hidden && cell[0] && cell.css('display') != 'none') {
       // Add 1 to our indexes. The nth-child selector is 1 based, not 0 based.
-      var columnIndex = $('td', field.parents('tr:first')).index(cell.get(0)) + 1;
-      var headerIndex = $('td:not(:hidden)', field.parents('tr:first')).index(cell.get(0)) + 1;
-      $('tbody tr', this.table).each(function() {
-        // Find and hide the cell in the table body.
-        var cell = $('td:nth-child('+ columnIndex +')', this);
-        if (cell.size()) {
-          cell.css('display', 'none');
-        }
-        // We might be dealing with a row spanning the entire table.
-        // Reduce the colspan on the first cell to prevent the cell from
-        // overshooting the table.
-        else {
-          cell = $('td:first', this);
-          cell.attr('colspan', cell.attr('colspan') - 1);
-        }
-      });
-      $('thead tr', this.table).each(function() {
-        // Remove table header cells entirely (Safari doesn't hide properly).
-        var th = $('th:nth-child('+ headerIndex +')', this);
-        if (th.size()) {
-          th.remove();
+      var columnIndex = $('td', cell.parent()).index(cell.get(0)) + 1;
+      var headerIndex = $('td:not(:hidden)', cell.parent()).index(cell.get(0)) + 1;
+      $('tr', this.table).each(function(){
+        var row = $(this);
+        var parentTag = row.parent().get(0).tagName.toLowerCase();
+        var index = (parentTag == 'thead') ? headerIndex : columnIndex;
+
+        // Adjust the index to take into account colspans.
+        row.children().each(function(n) {
+          if (n < index) {
+            index -= (this.colSpan && this.colSpan > 1) ? this.colSpan - 1 : 0;
+          }
+        });
+        if (index > 0) {
+          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;
+          }
+          else {
+            // Hide table body cells, but remove table header cells entirely
+            // (Safari doesn't hide properly).
+            parentTag == 'thead' ? cell.remove() : cell.css('display', 'none');
+          }
         }
       });
     }
@@ -411,6 +415,8 @@
       self.dragObject.indentMousePos.x += self.indentAmount * indentChange * self.rtl;
       self.indentCount = Math.max(self.indentCount, self.rowObject.indents);
     }
+
+    return false;
   }
 };