mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2024-12-27 09:28:56 +01:00
Merge pull request #507 from patriceac/patch-3
Modifier drag-and-drop plugin
This commit is contained in:
commit
aa98e60243
91
ui/plugins/ui/Modifiers-dnd.plugin.js
Normal file
91
ui/plugins/ui/Modifiers-dnd.plugin.js
Normal file
@ -0,0 +1,91 @@
|
||||
(function () {
|
||||
"use strict"
|
||||
|
||||
var styleSheet = document.createElement("style");
|
||||
styleSheet.textContent = `
|
||||
.modifier-card-tiny.drag-sort-active {
|
||||
background: transparent;
|
||||
border: 2px dashed white;
|
||||
opacity:0.2;
|
||||
}
|
||||
`;
|
||||
document.head.appendChild(styleSheet);
|
||||
|
||||
// observe for changes in tag list
|
||||
var observer = new MutationObserver(function (mutations) {
|
||||
// mutations.forEach(function (mutation) {
|
||||
if (editorModifierTagsList.childNodes.length > 0) {
|
||||
ModifierDragAndDrop(editorModifierTagsList)
|
||||
}
|
||||
// })
|
||||
})
|
||||
|
||||
observer.observe(editorModifierTagsList, {
|
||||
childList: true
|
||||
})
|
||||
|
||||
let current
|
||||
function ModifierDragAndDrop(target) {
|
||||
let overlays = document.querySelector('#editor-inputs-tags-list').querySelectorAll('.modifier-card-overlay')
|
||||
overlays.forEach (i => {
|
||||
i.parentElement.draggable = true;
|
||||
|
||||
i.parentElement.ondragstart = (e) => {
|
||||
current = i
|
||||
i.parentElement.getElementsByClassName('modifier-card-image-overlay')[0].innerText = ''
|
||||
i.parentElement.draggable = true
|
||||
i.parentElement.classList.add('drag-sort-active')
|
||||
for(let item of document.querySelector('#editor-inputs-tags-list').getElementsByClassName('modifier-card-image-overlay')) {
|
||||
if (item.parentElement.parentElement.getElementsByClassName('modifier-card-overlay')[0] != current) {
|
||||
item.parentElement.parentElement.getElementsByClassName('modifier-card-image-overlay')[0].style.opacity = 0
|
||||
if(item.parentElement.getElementsByClassName('modifier-card-image').length > 0) {
|
||||
item.parentElement.getElementsByClassName('modifier-card-image')[0].style.filter = 'none'
|
||||
}
|
||||
item.parentElement.parentElement.style.transform = 'none'
|
||||
item.parentElement.parentElement.style.boxShadow = 'none'
|
||||
}
|
||||
item.innerText = ''
|
||||
}
|
||||
}
|
||||
|
||||
i.ondragenter = (e) => {
|
||||
e.preventDefault()
|
||||
if (i != current) {
|
||||
let currentPos = 0, droppedPos = 0;
|
||||
for (let it = 0; it < overlays.length; it++) {
|
||||
if (current == overlays[it]) { currentPos = it; }
|
||||
if (i == overlays[it]) { droppedPos = it; }
|
||||
}
|
||||
|
||||
if (i.parentElement != current.parentElement) {
|
||||
let currentPos = 0, droppedPos = 0
|
||||
for (let it = 0; it < overlays.length; it++) {
|
||||
if (current == overlays[it]) { currentPos = it }
|
||||
if (i == overlays[it]) { droppedPos = it }
|
||||
}
|
||||
if (currentPos < droppedPos) {
|
||||
current = i.parentElement.parentNode.insertBefore(current.parentElement, i.parentElement.nextSibling).getElementsByClassName('modifier-card-overlay')[0]
|
||||
} else {
|
||||
current = i.parentElement.parentNode.insertBefore(current.parentElement, i.parentElement).getElementsByClassName('modifier-card-overlay')[0]
|
||||
}
|
||||
// update activeTags
|
||||
const tag = activeTags.splice(currentPos, 1)
|
||||
activeTags.splice(droppedPos, 0, tag[0])
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
i.ondragover = (e) => {
|
||||
e.preventDefault()
|
||||
}
|
||||
|
||||
i.parentElement.ondragend = (e) => {
|
||||
i.parentElement.classList.remove('drag-sort-active')
|
||||
for(let item of document.querySelector('#editor-inputs-tags-list').getElementsByClassName('modifier-card-image-overlay')) {
|
||||
item.style.opacity = ''
|
||||
item.innerText = '-'
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})()
|
Loading…
Reference in New Issue
Block a user