comparison 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
comparison
equal deleted inserted replaced
6:2cfdc3c92142 7:fff6d4c8c043
1 // $Id: tabledrag.js,v 1.13.2.1 2008/02/08 18:54:10 goba Exp $ 1 // $Id: tabledrag.js,v 1.13.2.3 2008/06/12 19:13:25 dries Exp $
2 2
3 /** 3 /**
4 * Drag and drop table rows with field manipulation. 4 * Drag and drop table rows with field manipulation.
5 * 5 *
6 * Using the drupal_add_tabledrag() function, any table with weights or parent 6 * Using the drupal_add_tabledrag() function, any table with weights or parent
85 // Hide columns containing affected form elements. 85 // Hide columns containing affected form elements.
86 this.hideColumns(); 86 this.hideColumns();
87 87
88 // Add mouse bindings to the document. The self variable is passed along 88 // Add mouse bindings to the document. The self variable is passed along
89 // as event handlers do not have direct access to the tableDrag object. 89 // as event handlers do not have direct access to the tableDrag object.
90 $(document).bind('mousemove', function(event) { self.dragRow(event, self); return false; }); 90 $(document).bind('mousemove', function(event) { return self.dragRow(event, self); });
91 $(document).bind('mouseup', function(event) { self.dropRow(event, self); }); 91 $(document).bind('mouseup', function(event) { return self.dropRow(event, self); });
92 }; 92 };
93 93
94 /** 94 /**
95 * Hide the columns containing form elements according to the settings for 95 * Hide the columns containing form elements according to the settings for
96 * this tableDrag instance. 96 * this tableDrag instance.
97 */ 97 */
98 Drupal.tableDrag.prototype.hideColumns = function() { 98 Drupal.tableDrag.prototype.hideColumns = function(){
99 for (var group in this.tableSettings) { 99 for (var group in this.tableSettings) {
100 // Find the first field in this group. 100 // Find the first field in this group.
101 for (var d in this.tableSettings[group]) { 101 for (var d in this.tableSettings[group]) {
102 if ($('.' + this.tableSettings[group][d]['target'], this.table).size()) { 102 var field = $('.' + this.tableSettings[group][d]['target'] + ':first', this.table);
103 if (field.size() && this.tableSettings[group][d]['hidden']) {
103 var hidden = this.tableSettings[group][d]['hidden']; 104 var hidden = this.tableSettings[group][d]['hidden'];
104 var field = $('.' + this.tableSettings[group][d]['target'] + ':first', this.table); 105 var cell = field.parents('td:first');
105 var cell = field.parents('td:first, th:first');
106 break; 106 break;
107 } 107 }
108 } 108 }
109
109 // Hide the column containing this field. 110 // Hide the column containing this field.
110 if (hidden && cell[0] && cell.css('display') != 'none') { 111 if (hidden && cell[0] && cell.css('display') != 'none') {
111 // Add 1 to our indexes. The nth-child selector is 1 based, not 0 based. 112 // Add 1 to our indexes. The nth-child selector is 1 based, not 0 based.
112 var columnIndex = $('td', field.parents('tr:first')).index(cell.get(0)) + 1; 113 var columnIndex = $('td', cell.parent()).index(cell.get(0)) + 1;
113 var headerIndex = $('td:not(:hidden)', field.parents('tr:first')).index(cell.get(0)) + 1; 114 var headerIndex = $('td:not(:hidden)', cell.parent()).index(cell.get(0)) + 1;
114 $('tbody tr', this.table).each(function() { 115 $('tr', this.table).each(function(){
115 // Find and hide the cell in the table body. 116 var row = $(this);
116 var cell = $('td:nth-child('+ columnIndex +')', this); 117 var parentTag = row.parent().get(0).tagName.toLowerCase();
117 if (cell.size()) { 118 var index = (parentTag == 'thead') ? headerIndex : columnIndex;
118 cell.css('display', 'none'); 119
119 } 120 // Adjust the index to take into account colspans.
120 // We might be dealing with a row spanning the entire table. 121 row.children().each(function(n) {
121 // Reduce the colspan on the first cell to prevent the cell from 122 if (n < index) {
122 // overshooting the table. 123 index -= (this.colSpan && this.colSpan > 1) ? this.colSpan - 1 : 0;
123 else { 124 }
124 cell = $('td:first', this); 125 });
125 cell.attr('colspan', cell.attr('colspan') - 1); 126 if (index > 0) {
126 } 127 cell = row.children(':nth-child(' + index + ')');
127 }); 128 if (cell[0].colSpan > 1) {
128 $('thead tr', this.table).each(function() { 129 // If this cell has a colspan, simply reduce it.
129 // Remove table header cells entirely (Safari doesn't hide properly). 130 cell[0].colSpan = cell[0].colSpan - 1;
130 var th = $('th:nth-child('+ headerIndex +')', this); 131 }
131 if (th.size()) { 132 else {
132 th.remove(); 133 // Hide table body cells, but remove table header cells entirely
134 // (Safari doesn't hide properly).
135 parentTag == 'thead' ? cell.remove() : cell.css('display', 'none');
136 }
133 } 137 }
134 }); 138 });
135 } 139 }
136 } 140 }
137 }; 141 };
409 var indentChange = self.rowObject.indent(indentDiff); 413 var indentChange = self.rowObject.indent(indentDiff);
410 // Update table and mouse indentations. 414 // Update table and mouse indentations.
411 self.dragObject.indentMousePos.x += self.indentAmount * indentChange * self.rtl; 415 self.dragObject.indentMousePos.x += self.indentAmount * indentChange * self.rtl;
412 self.indentCount = Math.max(self.indentCount, self.rowObject.indents); 416 self.indentCount = Math.max(self.indentCount, self.rowObject.indents);
413 } 417 }
418
419 return false;
414 } 420 }
415 }; 421 };
416 422
417 /** 423 /**
418 * Mouseup event handler, bound to document. 424 * Mouseup event handler, bound to document.