diff options
author | Paul Bakaus <paul.bakaus@googlemail.com> | 2009-01-08 15:49:20 +0000 |
---|---|---|
committer | Paul Bakaus <paul.bakaus@googlemail.com> | 2009-01-08 15:49:20 +0000 |
commit | c8305ae076239f7b920d421ce117d3c599c176eb (patch) | |
tree | 1236f14bd3ea4d5affbbfa90ff7c92ef3cc8e743 | |
parent | 72f7945a3fecce994b4dc480dbb5b94b7f1de967 (diff) | |
download | jquery-ui-c8305ae076239f7b920d421ce117d3c599c176eb.tar.gz jquery-ui-c8305ae076239f7b920d421ce117d3c599c176eb.zip |
sortable,draggable: fixed order and propagation of events (fixes #3658, #3730 and #3726)
-rw-r--r-- | ui/ui.draggable.js | 25 | ||||
-rw-r--r-- | ui/ui.sortable.js | 50 |
2 files changed, 39 insertions, 36 deletions
diff --git a/ui/ui.draggable.js b/ui/ui.draggable.js index 5e429b5fb..a1ffd20e7 100644 --- a/ui/ui.draggable.js +++ b/ui/ui.draggable.js @@ -104,7 +104,7 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, { this._setContainment(); //Call plugins and callbacks - this._propagate("start", event); + this._trigger("start", event); //Recache the helper size this._cacheHelperProportions(); @@ -130,7 +130,7 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, { */ //Call plugins and callbacks and use the resulting position if something is returned - if(!noPropagation) this.position = this._propagate("drag", event) || this.position; + if(!noPropagation) this.position = this._trigger("drag", event) || this.position; if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px'; if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px'; @@ -155,11 +155,11 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, { if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) { var self = this; $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() { - self._propagate("stop", event); + self._trigger("stop", event); self._clear(); }); } else { - this._propagate("stop", event); + this._trigger("stop", event); this._clear(); } @@ -373,10 +373,10 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, { // From now on bulk stuff - mainly helpers - _propagate: function(n, event) { - $.ui.plugin.call(this, n, [event, this._uiHash()]); - if(n == "drag") this.positionAbs = this._convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins - this._trigger(n, event, this._uiHash()); + _trigger: function(type, event) { + $.ui.plugin.call(this, type, [event, this._uiHash()]); + if(type == "drag") this.positionAbs = this._convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins + $.widget.prototype._trigger.call(this, type, event, this._uiHash()); return event.returnValue; }, @@ -443,7 +443,7 @@ $.ui.plugin.add("draggable", "connectToSortable", { shouldRevert: sortable.options.revert }); sortable._refreshItems(); //Do a one-time refresh at start to refresh the containerCache - sortable._propagate("activate", event, inst); + sortable._trigger("activate", event, inst); } }); }); @@ -479,7 +479,7 @@ $.ui.plugin.add("draggable", "connectToSortable", { } else { this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance - this.instance._propagate("deactivate", event, inst); + this.instance._trigger("deactivate", event, inst); } }); @@ -522,8 +522,9 @@ $.ui.plugin.add("draggable", "connectToSortable", { this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left; this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top; - inst._propagate("toSortable", event); + inst._trigger("toSortable", event); inst.dropped = this.instance.element; //draggable revert needs that + this.instance.fromOutside = true; //Little hack so receive/update callbacks work } @@ -545,7 +546,7 @@ $.ui.plugin.add("draggable", "connectToSortable", { this.instance.currentItem.remove(); if(this.instance.placeholder) this.instance.placeholder.remove(); - inst._propagate("fromSortable", event); + inst._trigger("fromSortable", event); inst.dropped = false; //draggable revert needs that } diff --git a/ui/ui.sortable.js b/ui/ui.sortable.js index 58e36191c..f022d00ea 100644 --- a/ui/ui.sortable.js +++ b/ui/ui.sortable.js @@ -148,7 +148,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { this._setContainment(); //Call plugins and callbacks - this._propagate("start", event); + this._trigger("start", event); //Recache the helper size if(!this._preserveHelperProportions) @@ -157,7 +157,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { //Post 'activate' events to possible containers if(!noActivation) { - for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._propagate("activate", event, this); } + for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, this); } } //Prepare possible droppables @@ -216,7 +216,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { break; } - this._propagate("change", event); //Call plugins and callbacks + this._trigger("change", event); //Call plugins and callbacks break; } } @@ -276,9 +276,9 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { //Post deactivating events to containers for (var i = this.containers.length - 1; i >= 0; i--){ - this.containers[i]._propagate("deactivate", null, this); + this.containers[i]._trigger("deactivate", null, this); if(this.containers[i].containerCache.over) { - this.containers[i]._propagate("out", null, this); + this.containers[i]._trigger("out", null, this); this.containers[i].containerCache.over = 0; } } @@ -608,20 +608,20 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { this.currentContainer = this.containers[i]; itemWithLeastDistance ? this.options.sortIndicator.call(this, event, itemWithLeastDistance, null, true) : this.options.sortIndicator.call(this, event, null, this.containers[i].element, true); - this._propagate("change", event); //Call plugins and callbacks - this.containers[i]._propagate("change", event, this); //Call plugins and callbacks + this._trigger("change", event); //Call plugins and callbacks + this.containers[i]._trigger("change", event, this); //Call plugins and callbacks //Update the placeholder this.options.placeholder.update(this.currentContainer, this.placeholder); } - this.containers[i]._propagate("over", event, this); + this.containers[i]._trigger("over", event, this); this.containers[i].containerCache.over = 1; } } else { if(this.containers[i].containerCache.over) { - this.containers[i]._propagate("out", event, this); + this.containers[i]._trigger("out", event, this); this.containers[i].containerCache.over = 0; } } @@ -828,49 +828,51 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { this.currentItem.show(); } - if(this.domPosition.prev != this.currentItem.prev().not("."+this.options.cssNamespace+"-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) this._propagate("update", event, null, noPropagation); //Trigger update callback if the DOM position has changed + if(this.fromOutside) this._trigger("receive", event, this, noPropagation); + if(this.fromOutside || this.domPosition.prev != this.currentItem.prev().not("."+this.options.cssNamespace+"-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) this._trigger("update", event, null, noPropagation); //Trigger update callback if the DOM position has changed if(!$.ui.contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element - this._propagate("remove", event, null, noPropagation); + this._trigger("remove", event, null, noPropagation); for (var i = this.containers.length - 1; i >= 0; i--){ if($.ui.contains(this.containers[i].element[0], this.currentItem[0])) { - this.containers[i]._propagate("update", event, this, noPropagation); - this.containers[i]._propagate("receive", event, this, noPropagation); + this.containers[i]._trigger("receive", event, this, noPropagation); + this.containers[i]._trigger("update", event, this, noPropagation); } }; }; //Post events to containers for (var i = this.containers.length - 1; i >= 0; i--){ - this.containers[i]._propagate("deactivate", event, this, noPropagation); + this.containers[i]._trigger("deactivate", event, this, noPropagation); if(this.containers[i].containerCache.over) { - this.containers[i]._propagate("out", event, this); + this.containers[i]._trigger("out", event, this); this.containers[i].containerCache.over = 0; } } this.dragging = false; if(this.cancelHelperRemoval) { - this._propagate("beforeStop", event, null, noPropagation); - this._propagate("stop", event, null, noPropagation); + this._trigger("beforeStop", event, null, noPropagation); + this._trigger("stop", event, null, noPropagation); return false; } - this._propagate("beforeStop", event, null, noPropagation); + this._trigger("beforeStop", event, null, noPropagation); //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node! this.placeholder[0].parentNode.removeChild(this.placeholder[0]); - if(this.options.helper != "original") this.helper.remove(); this.helper = null; - this._propagate("stop", event, null, noPropagation); + if(this.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null; + this._trigger("stop", event, null, noPropagation); + this.fromOutside = false; return true; }, - _propagate: function(n, event, inst, noPropagation) { - $.ui.plugin.call(this, n, [event, this._ui(inst)]); - var dontCancel = !noPropagation ? this.element.triggerHandler(n == "sort" ? n : "sort"+n, [event, this._ui(inst)], this.options[n]) : true; - if(dontCancel === false) this.cancel(); + _trigger: function(type, event, inst, noPropagation) { + $.ui.plugin.call(this, type, [event, this._ui(inst)]); + if(!noPropagation) $.widget.prototype._trigger.call(this, type, event, this._ui(inst)); + if(event.returnValue === false) this.cancel(); }, plugins: {}, |