diff options
author | Paul Bakaus <paul.bakaus@googlemail.com> | 2009-01-19 12:00:45 +0000 |
---|---|---|
committer | Paul Bakaus <paul.bakaus@googlemail.com> | 2009-01-19 12:00:45 +0000 |
commit | 5190908e61e0d8d360998a8643457bf13f8b3d1a (patch) | |
tree | a82990d837d01c12a6cb4535a396234bf0ec849b /ui | |
parent | 513f19e60bbbf20305e16fe7efdfc86aa157fdca (diff) | |
download | jquery-ui-5190908e61e0d8d360998a8643457bf13f8b3d1a.tar.gz jquery-ui-5190908e61e0d8d360998a8643457bf13f8b3d1a.zip |
sortable: all callbacks with the exception of the beforeStop callback now fire after everything has been normalized again (placeholder/helper removed, styles restored). (fixes #3864 and multiple user requests)
Diffstat (limited to 'ui')
-rw-r--r-- | ui/ui.sortable.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/ui/ui.sortable.js b/ui/ui.sortable.js index a51c20f5b..e99334f80 100644 --- a/ui/ui.sortable.js +++ b/ui/ui.sortable.js @@ -888,6 +888,9 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { _clear: function(event, noPropagation) { this.reverting = false; + // We delay all events that have to be triggered to after the point where the placeholder has been removed and + // everything else normalized again + var delayedTriggers = [], self = this; //We first have to update the dom position of the actual currentItem if(!this._noFinalSort) this.placeholder.before(this.currentItem); @@ -902,23 +905,23 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { this.currentItem.show(); } - if(this.fromOutside && !noPropagation) this._trigger("receive", event, this._uiHash(this.fromOutside)); - if((this.fromOutside || this.domPosition.prev != this.currentItem.prev().not("."+this.options.cssNamespace+"-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) && !noPropagation) this._trigger("update", event, this._uiHash()); //Trigger update callback if the DOM position has changed + if(this.fromOutside && !noPropagation) delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); }); + if((this.fromOutside || this.domPosition.prev != this.currentItem.prev().not("."+this.options.cssNamespace+"-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) && !noPropagation) delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //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 - if(!noPropagation) this._trigger("remove", event, this._uiHash()); + if(!noPropagation) delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); }); for (var i = this.containers.length - 1; i >= 0; i--){ if($.ui.contains(this.containers[i].element[0], this.currentItem[0]) && !noPropagation) { - this.containers[i]._trigger("receive", event, this._uiHash(this)); - this.containers[i]._trigger("update", event, this._uiHash(this)); + delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.containers[i])); + delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.containers[i])); } }; }; //Post events to containers for (var i = this.containers.length - 1; i >= 0; i--){ - if(!noPropagation) this.containers[i]._trigger("deactivate", event, this._uiHash(this)); + if(!noPropagation) delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); }; }).call(this, this.containers[i])); if(this.containers[i].containerCache.over) { - this.containers[i]._trigger("out", event, this._uiHash(this)); + delayedTriggers.push((function(c) { return function(event) { c._trigger("out", event, this._uiHash(this)); }; }).call(this, this.containers[i])); this.containers[i].containerCache.over = 0; } } @@ -932,6 +935,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { if(this.cancelHelperRemoval) { if(!noPropagation) { this._trigger("beforeStop", event, this._uiHash()); + for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events this._trigger("stop", event, this._uiHash()); } return false; @@ -943,7 +947,11 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, { this.placeholder[0].parentNode.removeChild(this.placeholder[0]); if(this.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null; - if(!noPropagation) this._trigger("stop", event, this._uiHash()); + + if(!noPropagation) { + for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events + this._trigger("stop", event, this._uiHash()); + } this.fromOutside = false; return true; |