From a56e305c2e455301892cd27c6fa7beaa75f6a90f Mon Sep 17 00:00:00 2001
From: Oscar Perez
Date: Fri, 17 Jan 2014 01:04:06 -0500
Subject: [PATCH 1/3] Added ability to skip items with disabledClass. Useful
when sorting over hidden/non-visible items.
---
jquery.mjs.nestedSortable.js | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/jquery.mjs.nestedSortable.js b/jquery.mjs.nestedSortable.js
index 72ed56b..4aea721 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() {
@@ -257,7 +258,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 +271,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 {
From 3b0313266a6c64a5968e009ca96b4130f0317fc3 Mon Sep 17 00:00:00 2001
From: Oscar Perez
Date: Fri, 17 Jan 2014 10:08:59 -0500
Subject: [PATCH 2/3] Added disabledClass option to README.
---
README.md | 2 ++
1 file changed, 2 insertions(+)
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
From 4fa262d1cba457f074882056e1aff9d0a7c1b8cf Mon Sep 17 00:00:00 2001
From: Oscar Perez
Date: Fri, 17 Jan 2014 12:25:42 -0500
Subject: [PATCH 3/3] Fixed skipping over disabled elements when they are
visible.
---
jquery.mjs.nestedSortable.js | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/jquery.mjs.nestedSortable.js b/jquery.mjs.nestedSortable.js
index 4aea721..5524936 100644
--- a/jquery.mjs.nestedSortable.js
+++ b/jquery.mjs.nestedSortable.js
@@ -179,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