Skip to content

Commit a7a4ef6

Browse files
committed
disableParentChange option added.
To be able to disable changing parentship but allow reordering in current parent. I use it for menu ordering of pages, where pages define parentship and a menu defines the sort order
1 parent 5a4675d commit a7a4ef6

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)