diff --git a/README.md b/README.md
index 57fab08..91cd8fe 100644
--- a/README.md
+++ b/README.md
@@ -109,6 +109,8 @@ Also, the default list type is `
`.
- Given to collapsed branches when dragging an item over them. Default: mjs-nestedSortable-hovering
- leafClass (2.0)
-
- Given to items that do not have children. Default: mjs-nestedSortable-leaf
+ - disabledClass (2.0)
-
+
- Given to items that should be skipped when sorting over them. For example, non-visible items that are still part of the list. Default: mjs-nestedSortable-disabled
## Custom Methods
diff --git a/jquery.mjs.nestedSortable.js b/jquery.mjs.nestedSortable.js
index 72ed56b..5524936 100644
--- a/jquery.mjs.nestedSortable.js
+++ b/jquery.mjs.nestedSortable.js
@@ -38,7 +38,8 @@
errorClass: 'mjs-nestedSortable-error',
expandedClass: 'mjs-nestedSortable-expanded',
hoveringClass: 'mjs-nestedSortable-hovering',
- leafClass: 'mjs-nestedSortable-leaf'
+ leafClass: 'mjs-nestedSortable-leaf',
+ disabledClass: 'mjs-nestedSortable-disabled'
},
_create: function() {
@@ -178,6 +179,27 @@
continue;
}
+ // No action if intersected item is disabled
+ // and the element above or below in the direction we're going is also disabled
+ if (itemElement.className.indexOf(o.disabledClass) !== -1) {
+ // Note: intersection hardcoded direction values from jquery.ui.sortable.js:_intersectsWithPointer
+ if (intersection === 2) {
+ // Going down
+ var itemAfter = this.items[i + 1];
+ if (itemAfter && itemAfter.item[0].className.indexOf(o.disabledClass) !== -1){
+ continue;
+ }
+
+ }
+ else if (intersection === 1) {
+ // Going up
+ var itemBefore = this.items[i - 1];
+ if (itemBefore && itemBefore.item[0].className.indexOf(o.disabledClass) !== -1){
+ continue;
+ }
+ }
+ }
+
// cannot intersect with itself
// no useless actions that have been done before
// no action if the item moved is the parent of the item checked
@@ -257,7 +279,7 @@
// mjs - to find the previous sibling in the list, keep backtracking until we hit a valid list item.
var previousItem = this.placeholder[0].previousSibling ? $(this.placeholder[0].previousSibling) : null;
if (previousItem != null) {
- while (previousItem[0].nodeName.toLowerCase() != 'li' || previousItem[0] == this.currentItem[0] || previousItem[0] == this.helper[0]) {
+ while (previousItem[0].nodeName.toLowerCase() != 'li' || previousItem[0].className.indexOf(o.disabledClass) !== -1 || previousItem[0] == this.currentItem[0] || previousItem[0] == this.helper[0]) {
if (previousItem[0].previousSibling) {
previousItem = $(previousItem[0].previousSibling);
} else {
@@ -270,7 +292,7 @@
// mjs - to find the next sibling in the list, keep stepping forward until we hit a valid list item.
var nextItem = this.placeholder[0].nextSibling ? $(this.placeholder[0].nextSibling) : null;
if (nextItem != null) {
- while (nextItem[0].nodeName.toLowerCase() != 'li' || nextItem[0] == this.currentItem[0] || nextItem[0] == this.helper[0]) {
+ while (nextItem[0].nodeName.toLowerCase() != 'li' || nextItem[0].className.indexOf(o.disabledClass) !== -1 || nextItem[0] == this.currentItem[0] || nextItem[0] == this.helper[0]) {
if (nextItem[0].nextSibling) {
nextItem = $(nextItem[0].nextSibling);
} else {