From f34df739a1898c5282bbc0d0b84362717cd1caa0 Mon Sep 17 00:00:00 2001 From: Nils Heuermann Date: Fri, 31 Oct 2014 14:24:29 +0100 Subject: [PATCH 1/5] Sortable: Append a tr with td to the placeholder of tbody elements When sorting tbody elements of a table the placeholder needs to have a tr with td elements to be visible. The appended elements are created in the same way as for the placeholder of a tr element; the first row of the sorted tbody is used for that. --- ui/sortable.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ui/sortable.js b/ui/sortable.js index 0207c86206d..466ce7931a1 100644 --- a/ui/sortable.js +++ b/ui/sortable.js @@ -788,12 +788,12 @@ return $.widget("ui.sortable", $.ui.mouse, { .addClass(className || that.currentItem[0].className+" ui-sortable-placeholder") .removeClass("ui-sortable-helper"); - if ( nodeName === "tr" ) { - that.currentItem.children().each(function() { - $( " ", that.document[0] ) - .attr( "colspan", $( this ).attr( "colspan" ) || 1 ) - .appendTo( element ); - }); + if ( nodeName === "tbody" ) { + var tr = $( "", that.document[0] ) + .appendTo( element ) ; + that._createTrPlaceholder( that, that.currentItem.find('tr:first'), tr ); + } else if ( nodeName === "tr" ) { + that._createTrPlaceholder( that, that.currentItem, element ); } else if ( nodeName === "img" ) { element.attr( "src", that.currentItem.attr( "src" ) ); } @@ -830,6 +830,16 @@ return $.widget("ui.sortable", $.ui.mouse, { }, + _createTrPlaceholder: function(that, sourceTr, targetTr) { + that = that || this; + + sourceTr.children().each(function() { + $( " ", that.document[0] ) + .attr( "colspan", $( this ).attr( "colspan" ) || 1 ) + .appendTo( targetTr ); + }); + }, + _contactContainers: function(event) { var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, cur, nearBottom, floating, axis, innermostContainer = null, From d85084136adbbf9956c4312de1b877b983bbd79a Mon Sep 17 00:00:00 2001 From: Nils Heuermann Date: Mon, 3 Nov 2014 09:13:48 +0100 Subject: [PATCH 2/5] Sortable: Minor changes to satisfy jshint --- ui/sortable.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ui/sortable.js b/ui/sortable.js index 466ce7931a1..03df0d2387d 100644 --- a/ui/sortable.js +++ b/ui/sortable.js @@ -776,7 +776,8 @@ return $.widget("ui.sortable", $.ui.mouse, { _createPlaceholder: function(that) { that = that || this; var className, - o = that.options; + o = that.options, + tr; if(!o.placeholder || o.placeholder.constructor === String) { className = o.placeholder; @@ -789,9 +790,9 @@ return $.widget("ui.sortable", $.ui.mouse, { .removeClass("ui-sortable-helper"); if ( nodeName === "tbody" ) { - var tr = $( "", that.document[0] ) + tr = $( "", that.document[0] ) .appendTo( element ) ; - that._createTrPlaceholder( that, that.currentItem.find('tr:first'), tr ); + that._createTrPlaceholder( that, that.currentItem.find( "tr:first" ), tr ); } else if ( nodeName === "tr" ) { that._createTrPlaceholder( that, that.currentItem, element ); } else if ( nodeName === "img" ) { From 69f2b9aceda6f8b51b0afc7ffce0b54b4d30be8a Mon Sep 17 00:00:00 2001 From: Nils Heuermann Date: Mon, 3 Nov 2014 09:15:40 +0100 Subject: [PATCH 3/5] Sortable Tests: Added test for tbody placeholder --- tests/unit/sortable/sortable.html | 52 +++++++++++++++++++++---- tests/unit/sortable/sortable_options.js | 36 +++++++++++++++++ 2 files changed, 80 insertions(+), 8 deletions(-) diff --git a/tests/unit/sortable/sortable.html b/tests/unit/sortable/sortable.html index 3edc999b76e..f13b895b8db 100644 --- a/tests/unit/sortable/sortable.html +++ b/tests/unit/sortable/sortable.html @@ -74,20 +74,56 @@ - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
121.11.2
341.31.4
561.51.6
781.71.8
2.12.2
2.32.4
2.52.6
2.72.8
3.13.2
3.33.4
3.53.6
3.73.8
diff --git a/tests/unit/sortable/sortable_options.js b/tests/unit/sortable/sortable_options.js index f2beb4dbcd6..90cf765a2b5 100644 --- a/tests/unit/sortable/sortable_options.js +++ b/tests/unit/sortable/sortable_options.js @@ -388,6 +388,42 @@ test( "{ placholder: String } tr", function() { }); }); +test( "{ placholder: String } tbody", function() { + expect( 6 ); + + var originalWidths, + element = $( "#sortable-table" ).sortable({ + placeholder: "test", + start: function( event, ui ) { + var currentWidths = otherBody.children().map(function() { + return $( this ).width(); + }).get(); + ok( ui.placeholder.hasClass( "test" ), "placeholder has class" ); + deepEqual( currentWidths, originalWidths, "table cells maintain size" ); + equal( ui.placeholder.children().length, 1, + "placeholder has one child" ); + equal( ui.placeholder.children( "tr" ).length, 1, + "placeholder's child is tr" ); + equal( ui.placeholder.find( "> tr" ).children().length, + dragBody.find( "> tr:first" ).children().length, + "placeholder's tr has correct number of cells" ); + equal( ui.placeholder.find( "> tr" ).children().html(), + $( " " ).html(), + "placeholder td has content for forced dimensions" ); + } + }), + bodies = element.children( "tbody" ), + dragBody = bodies.eq( 0 ), + otherBody = bodies.eq( 1 ); + + originalWidths = otherBody.children().map(function() { + return $( this ).width(); + }).get(); + dragBody.simulate( "drag", { + dy: 1 + }); +}); + /* test("{ revert: false }, default", function() { ok(false, "missing test - untested code is broken code."); From 63ecea7734982b142437ab59177846e0aa3eb394 Mon Sep 17 00:00:00 2001 From: Nils Heuermann Date: Thu, 5 Feb 2015 11:17:40 +0100 Subject: [PATCH 4/5] Sortable: Minor code adjustments for tbody placeholder --- ui/sortable.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/ui/sortable.js b/ui/sortable.js index 03df0d2387d..c9698449d2b 100644 --- a/ui/sortable.js +++ b/ui/sortable.js @@ -776,8 +776,7 @@ return $.widget("ui.sortable", $.ui.mouse, { _createPlaceholder: function(that) { that = that || this; var className, - o = that.options, - tr; + o = that.options; if(!o.placeholder || o.placeholder.constructor === String) { className = o.placeholder; @@ -790,11 +789,9 @@ return $.widget("ui.sortable", $.ui.mouse, { .removeClass("ui-sortable-helper"); if ( nodeName === "tbody" ) { - tr = $( "", that.document[0] ) - .appendTo( element ) ; - that._createTrPlaceholder( that, that.currentItem.find( "tr:first" ), tr ); + that._createTrPlaceholder( that.currentItem.find( "tr:first" ), $( "", that.document[0] ).appendTo( element ) ); } else if ( nodeName === "tr" ) { - that._createTrPlaceholder( that, that.currentItem, element ); + that._createTrPlaceholder( that.currentItem, element ); } else if ( nodeName === "img" ) { element.attr( "src", that.currentItem.attr( "src" ) ); } @@ -831,8 +828,8 @@ return $.widget("ui.sortable", $.ui.mouse, { }, - _createTrPlaceholder: function(that, sourceTr, targetTr) { - that = that || this; + _createTrPlaceholder: function( sourceTr, targetTr ) { + var that = this; sourceTr.children().each(function() { $( " ", that.document[0] ) From 7277353edc9e0fd51c36af725d3ed2e2bb9715d0 Mon Sep 17 00:00:00 2001 From: Nils Heuermann Date: Tue, 24 Feb 2015 08:54:55 +0100 Subject: [PATCH 5/5] Sortable: Some more code styling for tbody placeholder --- ui/sortable.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ui/sortable.js b/ui/sortable.js index c9698449d2b..63933fae7c9 100644 --- a/ui/sortable.js +++ b/ui/sortable.js @@ -789,7 +789,10 @@ return $.widget("ui.sortable", $.ui.mouse, { .removeClass("ui-sortable-helper"); if ( nodeName === "tbody" ) { - that._createTrPlaceholder( that.currentItem.find( "tr:first" ), $( "", that.document[0] ).appendTo( element ) ); + that._createTrPlaceholder( + that.currentItem.find( "tr" ).eq( 0 ), + $( "", that.document[ 0 ] ).appendTo( element ) + ); } else if ( nodeName === "tr" ) { that._createTrPlaceholder( that.currentItem, element ); } else if ( nodeName === "img" ) { @@ -832,7 +835,7 @@ return $.widget("ui.sortable", $.ui.mouse, { var that = this; sourceTr.children().each(function() { - $( " ", that.document[0] ) + $( " ", that.document[ 0 ] ) .attr( "colspan", $( this ).attr( "colspan" ) || 1 ) .appendTo( targetTr ); });