Skip to content

Commit

Permalink
Merge branch 'feat-revOnError' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mjsarfatti committed May 6, 2011
2 parents 1910608 + 2f630b3 commit a7e252b
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions jquery.ui.nestedSortable.js
Expand Up @@ -20,7 +20,8 @@
errorClass: 'ui-nestedSortable-error',
listType: 'ol',
maxLevels: 0,
noJumpFix: 0
noJumpFix: 0,
revertOnError: 1
},

_create: function(){
Expand Down Expand Up @@ -173,15 +174,27 @@

// If the item is in a position not allowed, send it back
if (this.beyondMaxLevels) {
var parent = this.placeholder.parent().closest(this.options.items);

for (var i = this.beyondMaxLevels - 1; i > 0; i--) {
parent = parent.parent().closest(this.options.items);
this.placeholder.removeClass(this.options.errorClass);

if (this.options.revertOnError) {
if (this.domPosition.prev) {
$(this.domPosition.prev).after(this.placeholder);
} else {
$(this.domPosition.parent).prepend(this.placeholder);
}
this._trigger("revert", event, this._uiHash());
} else {
var parent = this.placeholder.parent().closest(this.options.items);

for (var i = this.beyondMaxLevels - 1; i > 0; i--) {
parent = parent.parent().closest(this.options.items);
}

parent.after(this.placeholder);
this._trigger("change", event, this._uiHash());
}

this.placeholder.removeClass(this.options.errorClass);
parent.after(this.placeholder);
this._trigger("change", event, this._uiHash());
}

$.ui.sortable.prototype._mouseStop.apply(this, arguments);
Expand Down

0 comments on commit a7e252b

Please sign in to comment.