Tab-Search-and-Manage/src/scripts/dragContainersSetup.js

52 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-10-31 05:30:34 +00:00
let count = 2; toMoveID = 0, newIndex = 0;;
let insert = "";
let isDragging = false;
2018-04-20 06:06:32 +00:00
2019-05-04 23:12:22 +00:00
var drake = dragula({
direction: 'horizontal', // X axis is considered when determining where an element would be dropped
copy: false, // elements are moved by default, not copied
copySortSource: false, // elements in copy-source containers can be reordered
revertOnSpill: true, // spilling will put the element back where it was dragged from, if this is true
removeOnSpill: false, // spilling will `.remove` the element, if this is true
ignoreInputTextSelection: true // allows users to select input text, see details below
}).on('drag', function (el) {
2020-10-31 05:30:34 +00:00
isDragging = true;
toMoveID = parseInt(el.getAttribute("tabID"));
2018-04-20 06:06:32 +00:00
el.className = el.className.replace('ex-moved', '');
}).on('drop', function (el, container) {
var subCont = document.getElementById("listZone");
var size = subCont.children.length;
for (var i = 0; i < size; i++) {
if (subCont.children[i].getAttribute("tabID") == toMoveID) {
newIndex = i;
}
}
2020-10-31 05:30:34 +00:00
isDragging = false;
2018-05-06 01:02:50 +00:00
tabsAction.move(toMoveID, {index: newIndex}).then();
2018-04-20 06:06:32 +00:00
el.className += ' ex-moved';
}).on('over', function (el, container) {
container.className += ' ex-over';
}).on('out', function (el, container) {
container.className = container.className.replace('ex-over', '');
});
2020-10-31 05:30:34 +00:00
drake.on("cancel", (el, container, source) => {
isDragging = false;
el.scrollIntoView();
let i = 0;
while( (el = el.previousSibling) != null ) {
i++;
}
if (i < (container.children.length - 6)) {
container.scrollBy(0, -100); // Go up 100px
}
});
2018-04-20 06:06:32 +00:00
// Connect to pre created containers
drake.containers.push(document.querySelector('#listZone'));