]> source.dussan.org Git - jquery-ui.git/commitdiff
sortable: all callbacks with the exception of the beforeStop callback now fire after...
authorPaul Bakaus <paul.bakaus@googlemail.com>
Mon, 19 Jan 2009 12:00:45 +0000 (12:00 +0000)
committerPaul Bakaus <paul.bakaus@googlemail.com>
Mon, 19 Jan 2009 12:00:45 +0000 (12:00 +0000)
ui/ui.sortable.js

index a51c20f5b2a73e7f88658df20d604e5f654a4e95..e99334f80a82721ad40284c440aecd4950408d99 100644 (file)
@@ -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;