mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
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)
This commit is contained in:
parent
513f19e60b
commit
5190908e61
@ -888,6 +888,9 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
_clear: function(event, noPropagation) {
|
_clear: function(event, noPropagation) {
|
||||||
|
|
||||||
this.reverting = false;
|
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
|
//We first have to update the dom position of the actual currentItem
|
||||||
if(!this._noFinalSort) this.placeholder.before(this.currentItem);
|
if(!this._noFinalSort) this.placeholder.before(this.currentItem);
|
||||||
@ -902,23 +905,23 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
this.currentItem.show();
|
this.currentItem.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.fromOutside && !noPropagation) this._trigger("receive", event, this._uiHash(this.fromOutside));
|
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) this._trigger("update", event, this._uiHash()); //Trigger update callback if the DOM position has changed
|
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(!$.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--){
|
for (var i = this.containers.length - 1; i >= 0; i--){
|
||||||
if($.ui.contains(this.containers[i].element[0], this.currentItem[0]) && !noPropagation) {
|
if($.ui.contains(this.containers[i].element[0], this.currentItem[0]) && !noPropagation) {
|
||||||
this.containers[i]._trigger("receive", event, this._uiHash(this));
|
delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
|
||||||
this.containers[i]._trigger("update", event, this._uiHash(this));
|
delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
//Post events to containers
|
//Post events to containers
|
||||||
for (var i = this.containers.length - 1; i >= 0; i--){
|
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) {
|
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;
|
this.containers[i].containerCache.over = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -932,6 +935,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
if(this.cancelHelperRemoval) {
|
if(this.cancelHelperRemoval) {
|
||||||
if(!noPropagation) {
|
if(!noPropagation) {
|
||||||
this._trigger("beforeStop", event, this._uiHash());
|
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());
|
this._trigger("stop", event, this._uiHash());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -943,7 +947,11 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
|
this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
|
||||||
|
|
||||||
if(this.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null;
|
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;
|
this.fromOutside = false;
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user