From 15326c1ef2fd1352bfe6a189067effb3e0c593a6 Mon Sep 17 00:00:00 2001 From: Mehmet Can Alaca Date: Tue, 29 May 2018 22:10:02 -0600 Subject: [PATCH 1/2] Added ID-Based Duplicate Protection for Cloning Added ID-Based Duplicate Protection for Cloning --- Sortable.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index 8b32dfb29..06f61b054 100644 --- a/Sortable.js +++ b/Sortable.js @@ -264,7 +264,8 @@ disabled: false, store: null, handle: null, - scroll: true, + allowDuplicates: true, + scroll: true, scrollSensitivity: 30, scrollSpeed: 10, draggable: /[uo]l/i.test(el.nodeName) ? 'li' : '>*', @@ -819,6 +820,17 @@ } } else if (target && !target.animated && target !== dragEl && (target.parentNode[expando] !== void 0)) { + if (!options.allowDuplicates && el !== rootEl) { + var duplicates = el.querySelectorAll("#"+dragEl.id); + if (duplicates.length > 1) { + return; + } + if (duplicates.length == 1) { + if (!duplicates[0].classList.contains(options.ghostClass)) { + return; + } + } + } if (lastEl !== target) { lastEl = target; lastCSS = _css(target); From 5c9053235ac345135961695798ce67378ceb1d07 Mon Sep 17 00:00:00 2001 From: Mehmet Can Alaca Date: Wed, 30 May 2018 20:07:58 -0600 Subject: [PATCH 2/2] Added Destructive Group Ability --- Sortable.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sortable.js b/Sortable.js index 06f61b054..fb891edda 100644 --- a/Sortable.js +++ b/Sortable.js @@ -49,6 +49,7 @@ putSortable, autoScroll = {}, + destructive = false, tapEvt, touchEvt, @@ -265,6 +266,7 @@ store: null, handle: null, allowDuplicates: true, + isDestructive: false, scroll: true, scrollSensitivity: 30, scrollSpeed: 10, @@ -737,6 +739,8 @@ isMovingBetweenSortable = false, canSort = options.sort; + destructive = options.isDestructive; + if (evt.preventDefault !== void 0) { evt.preventDefault(); !options.dragoverBubble && evt.stopPropagation(); @@ -1001,6 +1005,9 @@ // drag from one list and drop into another _dispatchEvent(null, parentEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex, evt); _dispatchEvent(this, rootEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex, evt); + if (destructive) { + dragEl && dragEl.parentNode && dragEl.parentNode.removeChild(dragEl); + } } } else {