Skip to content

Commit c68bad7

Browse files
author
Matt Parnell
committed
Merge pull request ilikenwf#1 from twicejr/2.0alpha
disableParentChange option added.
2 parents 5a4675d + a7a4ef6 commit c68bad7

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

jquery.mjs.nestedSortable.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
$.widget("mjs.nestedSortable", $.extend({}, $.ui.sortable.prototype, {
2121

2222
options: {
23+
disableParentChange: false,
2324
doNotClear: false,
2425
expandOnHover: 700,
2526
isAllowed: function(placeholder, placeholderParent, originalItem) { return true; },
@@ -619,9 +620,15 @@
619620
var o = this.options,
620621
maxLevels = this.placeholder.closest('.ui-sortable').nestedSortable('option', 'maxLevels'); // this takes into account the maxLevels set to the recipient list
621622

623+
// Check if the parent has changed to prevent it, when o.disableParentChange is true
624+
var oldParent = this.currentItem.parent().parent();
625+
var disabledByParentchange = o.disableParentChange && (
626+
parentItem !== null && !oldParent.is(parentItem)//From somewhere to somewhere else, except the root
627+
|| parentItem === null && oldParent.is('li') //From somewhere to the root
628+
);
622629
// mjs - is the root protected?
623630
// mjs - are we nesting too deep?
624-
if ( ! o.isAllowed(this.placeholder, parentItem, this.currentItem)) {
631+
if (disabledByParentchange || ! o.isAllowed(this.placeholder, parentItem, this.currentItem)) {
625632
this.placeholder.addClass(o.errorClass);
626633
if (maxLevels < levels && maxLevels != 0) {
627634
this.beyondMaxLevels = levels - maxLevels;

0 commit comments

Comments
 (0)