From: Paul Bakaus Date: Thu, 29 May 2008 12:37:32 +0000 (+0000) Subject: sortable: connecting draggables to a sortable and dropping them on the sortable now... X-Git-Tag: 1.5.1~278 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2d6b7469cb81844ecf102db37a388e4cea77ef0f;p=jquery-ui.git sortable: connecting draggables to a sortable and dropping them on the sortable now also triggers a "receive" event, where the sender will be the original draggable. Moving out of the sortable while dragging a connected draggable will not trigger the stop/update events anymore. --- diff --git a/ui/source/ui.draggable.js b/ui/source/ui.draggable.js index 9131d9e40..7ef5f84e6 100644 --- a/ui/source/ui.draggable.js +++ b/ui/source/ui.draggable.js @@ -456,6 +456,10 @@ this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work) if(this.shouldRevert) this.instance.options.revert = true; //revert here this.instance.mouseStop(e); + + //Also propagate receive event, since the sortable is actually receiving a element + this.instance.element.triggerHandler("sortreceive", [e, $.extend(this.instance.ui(), { sender: inst.element })], this.instance.options["receive"]); + this.instance.options.helper = "original"; } }); @@ -514,7 +518,7 @@ this.instance.isOver = 0; this.instance.cancelHelperRemoval = true; this.instance.options.revert = false; //No revert here - this.instance.mouseStop(e); + this.instance.mouseStop(e, true); this.instance.options.helper = "original"; //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size diff --git a/ui/source/ui.sortable.js b/ui/source/ui.sortable.js index c0b15632e..7ab406a59 100644 --- a/ui/source/ui.sortable.js +++ b/ui/source/ui.sortable.js @@ -60,13 +60,15 @@ sender: inst ? inst.element : null }; }, - propagate: function(n,e,inst) { + propagate: function(n,e,inst, noPropagation) { $.ui.plugin.call(this, n, [e, this.ui(inst)]); - this.element.triggerHandler(n == "sort" ? n : "sort"+n, [e, this.ui(inst)], this.options[n]); + if(!noPropagation) this.element.triggerHandler(n == "sort" ? n : "sort"+n, [e, this.ui(inst)], this.options[n]); }, serialize: function(o) { - var items = $(this.options.items, this.element).not('.ui-sortable-helper'); //Only the items of the sortable itself + + + var items = ($.isFunction(this.options.items) ? this.options.items.call(this.element) : $(this.options.items, this.element)).not('.ui-sortable-helper'); //Only the items of the sortable itself var str = []; o = o || {}; items.each(function() { @@ -78,7 +80,7 @@ }, toArray: function(attr) { - var items = $(this.options.items, this.element).not('.ui-sortable-helper'); //Only the items of the sortable itself + var items = ($.isFunction(this.options.items) ? this.options.items.call(this.element) : $(this.options.items, this.element)).not('.ui-sortable-helper'); //Only the items of the sortable itself var ret = []; items.each(function() { ret.push($(this).attr(attr || 'id')); }); @@ -167,7 +169,7 @@ for (var j = cur.length - 1; j >= 0; j--){ var inst = $.data(cur[j], 'sortable'); if(inst && !inst.options.disabled) { - queries.push($.isFunction(inst.options.items) ? inst.options.items.call(this.element) : $(inst.options.items, inst.element)); + queries.push($.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element)); this.containers.push(inst); } }; @@ -495,7 +497,7 @@ return false; }, - mouseStop: function(e) { + mouseStop: function(e, noPropagation) { //If we are using droppables, inform the manager about the drop if ($.ui.ddmanager && !this.options.dropBehaviour) @@ -512,20 +514,20 @@ left: cur.left - this.offset.parent.left - self.margins.left + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft), top: cur.top - this.offset.parent.top - self.margins.top + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop) }, parseInt(this.options.revert, 10) || 500, function() { - self.propagate("stop", e); + self.propagate("stop", e, null, noPropagation); self.clear(e); }); } else { - this.propagate("stop", e); - this.clear(e); + this.propagate("stop", e, null, noPropagation); + this.clear(e, noPropagation); } return false; }, - clear: function(e) { + clear: function(e, noPropagation) { - if(this.domPosition != this.currentItem.prev()[0]) this.propagate("update", e); //Trigger update callback if the DOM position has changed + if(this.domPosition != this.currentItem.prev()[0]) this.propagate("update", e, null, noPropagation); //Trigger update callback if the DOM position has changed if(!contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element this.propagate("remove", e); for (var i = this.containers.length - 1; i >= 0; i--){