From 68f45613bd32d85cc55fbf77701f393799682bf2 Mon Sep 17 00:00:00 2001 From: Dave Stein Date: Thu, 20 Dec 2012 18:02:00 -0500 Subject: [PATCH] Draggable: Added stack backCompat --- ui/jquery.ui.draggable.js | 51 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js index 441e87bf7..78fa189f7 100644 --- a/ui/jquery.ui.draggable.js +++ b/ui/jquery.ui.draggable.js @@ -252,8 +252,7 @@ $.widget( "ui.draggable", $.ui.interaction, { }, _handleScrolling: function( pointerPosition ) { - var self = this, - scrollTop = this.scrollParent.scrollTop(), + var scrollTop = this.scrollParent.scrollTop(), scrollLeft = this.scrollParent.scrollLeft(), scrollSensitivity = this.scrollSensitivity, // overflowOffset is only set when scrollParent is not doc/html @@ -882,4 +881,52 @@ if ( $.uiBackCompat !== false ) { }); + // stack option + $.widget( "ui.draggable", $.ui.draggable, { + options: { + stack: false + }, + + _create: function() { + + var self = this; + + this._super(); + + this.element.on( "dragbeforestart", function( event, ui ) { + + var stack = self.options.stack, + group, min; + + if ( !self.options.stack ) { + return; + } + + group = $.makeArray( $(stack) ).sort(function(a,b) { + + var aZIndex = parseInt( $(a).css("zIndex"), 10 ), + bZIndex = parseInt( $(b).css("zIndex"), 10 ), + min; + + return ( aZIndex || 0) - ( bZIndex|| 0); + }); + + if (!group.length) { + return; + } + + min = parseInt(group[0].style.zIndex, 10) || 0; + + $(group).each(function(i) { + this.style.zIndex = min + i; + }); + + self.element[0].style.zIndex = min + group.length; + + }); + + } + + }); + } \ No newline at end of file