From c32bebd1bd28d158b017bb1dd7f95fb1d8a8d567 Mon Sep 17 00:00:00 2001 From: TJ VanToll Date: Mon, 11 Feb 2013 23:29:48 -0500 Subject: [PATCH] Draggable: Account for z-index set in CSS for the stack option. Fixed #9077 - Draggable: stack option resets the z-index --- tests/unit/draggable/draggable.html | 9 +++++- tests/unit/draggable/draggable_options.js | 35 +++++++++++++++++++++++ ui/jquery.ui.draggable.js | 7 ++--- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/tests/unit/draggable/draggable.html b/tests/unit/draggable/draggable.html index cd068eb20..50bed8caf 100644 --- a/tests/unit/draggable/draggable.html +++ b/tests/unit/draggable/draggable.html @@ -6,6 +6,12 @@ + + + @@ -39,13 +45,14 @@

    -
    Relative
    Absolute
    +
    +
    diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js index a3f7169f2..8496d6182 100644 --- a/tests/unit/draggable/draggable_options.js +++ b/tests/unit/draggable/draggable_options.js @@ -723,4 +723,39 @@ test("{ zIndex: 10 }", function() { }); +test( "{ stack }", function() { + expect( 4 ); + + var draggable1 = $( "#draggable1" ), + draggable2 = $( "#draggable2" ), + draggable3 = $( "#draggable3" ), + draggable4 = $( "#draggable4" ); + + // Set z-index as an inline style. + $( "#draggable1, #draggable2" ) + .css( "zIndex", 100 ) + .draggable({ + stack: "#draggable1, #draggable2" + }); + // Have z-index applied via CSS, see #9077 + $( "#draggable3, #draggable4" ) + .draggable({ + stack: "#draggable3, #draggable4" + }); + + draggable1.simulate( "drag", { + dx: 1, + dy: 1 + }); + draggable3.simulate( "drag", { + dx: 1, + dy: 1 + }); + + equal( draggable1.css( "zIndex" ), 102); + equal( draggable2.css( "zIndex" ), 101); + equal( draggable3.css( "zIndex" ), 102); + equal( draggable4.css( "zIndex" ), 101); +}); + })(jQuery); diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js index 9a31add7c..b8d21bd80 100644 --- a/ui/jquery.ui.draggable.js +++ b/ui/jquery.ui.draggable.js @@ -917,13 +917,12 @@ $.ui.plugin.add("draggable", "stack", { if (!group.length) { return; } - min = parseInt(group[0].style.zIndex, 10) || 0; + min = parseInt($(group[0]).css("zIndex"), 10) || 0; $(group).each(function(i) { - this.style.zIndex = min + i; + $(this).css("zIndex", min + i); }); - this[0].style.zIndex = min + group.length; - + $(this[0]).css("zIndex", (min + group.length)); } }); -- 2.39.5