summaryrefslogtreecommitdiff
path: root/misc/tabledrag.js
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-06-10 05:06:57 +0000
committerDries Buytaert <dries@buytaert.net>2009-06-10 05:06:57 +0000
commit122ba8461ee95aee906e933f0fed50e8c585087e (patch)
treee71a1fbb0cd67f7fd297bb636b16488072d3abae /misc/tabledrag.js
parentcf7371805eba6d5a82da9b88ee9cf8a7b1f4fa4c (diff)
downloadbrdo-122ba8461ee95aee906e933f0fed50e8c585087e.tar.gz
brdo-122ba8461ee95aee906e933f0fed50e8c585087e.tar.bz2
- Patch #329797 by danielb: better support for nested elements.
Diffstat (limited to 'misc/tabledrag.js')
-rw-r--r--misc/tabledrag.js16
1 files changed, 10 insertions, 6 deletions
diff --git a/misc/tabledrag.js b/misc/tabledrag.js
index 04e4b8bd4..db40f2437 100644
--- a/misc/tabledrag.js
+++ b/misc/tabledrag.js
@@ -79,13 +79,15 @@ Drupal.tableDrag = function (table, tableSettings) {
// manually append 2 indentations in the first draggable row, measure
// the offset, then remove.
var indent = Drupal.theme('tableDragIndentation');
- var testCell = $('tr.draggable:first td:first', table).prepend(indent).prepend(indent);
+ // Match immediate children of the parent element to allow nesting.
+ var testCell = $('> tbody > tr.draggable:first td:first, > tr.draggable:first td:first', table).prepend(indent).prepend(indent);
this.indentAmount = $('.indentation', testCell).get(1).offsetLeft - $('.indentation', testCell).get(0).offsetLeft;
$('.indentation', testCell).slice(0, 2).remove();
}
// Make each applicable row draggable.
- $('tr.draggable', table).each(function () { self.makeDraggable(this); });
+ // 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();
@@ -115,9 +117,10 @@ Drupal.tableDrag.prototype.hideColumns = function () {
// 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', cell.parent()).index(cell.get(0)) + 1;
- var headerIndex = $('td:not(:hidden)', cell.parent()).index(cell.get(0)) + 1;
- $('tr', this.table).each(function () {
+ // Match immediate children of the parent element to allow nesting.
+ var columnIndex = $('> td', cell.parent()).index(cell.get(0)) + 1;
+ var headerIndex = $('> td:not(:hidden)', cell.parent()).index(cell.get(0)) + 1;
+ $('> thead > tr, > tbody > tr, > tr', this.table).each(function(){
var row = $(this);
var parentTag = row.parent().get(0).tagName.toLowerCase();
var index = (parentTag == 'thead') ? headerIndex : columnIndex;
@@ -763,7 +766,8 @@ Drupal.tableDrag.prototype.setScroll = function (scrollAmount) {
Drupal.tableDrag.prototype.restripeTable = function () {
// :even and :odd are reversed because jQuery counts from 0 and
// we count from 1, so we're out of sync.
- $('tr.draggable', this.table)
+ // Match immediate children of the parent element to allow nesting.
+ $('> tbody > tr.draggable, > tr.draggable', this.table)
.filter(':odd').filter('.odd')
.removeClass('odd').addClass('even')
.end().end()