r1677 - trunk/ui

r1677 - trunk/ui


Author: paul.bakaus
Date: Mon Jan 19 04:00:45 2009
New Revision: 1677
Modified:
trunk/ui/ui.sortable.js
Log:
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)
Modified: trunk/ui/ui.sortable.js
==============================================================================
--- trunk/ui/ui.sortable.js    (original)
+++ trunk/ui/ui.sortable.js    Mon Jan 19 04:00:45 2009
@@ -888,6 +888,9 @@
    _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 @@
            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 @@
        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 @@
        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;