Fix regressions in draggable toolbar buttons.

This commit is contained in:
hackademix 2022-02-25 19:09:26 +01:00
parent e27718ace4
commit c8cfa0ba2a
2 changed files with 25 additions and 11 deletions

View File

@ -124,16 +124,17 @@ body {
display: block; display: block;
font-size: 1.2em; font-size: 1.2em;
font-weight: bold; font-weight: bold;
padding: 0; padding: .2em;
text-align: center; text-align: center;
margin: 0; margin: 0;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
border: none;
background: transparent;
} }
.hider.open > .reveal { .hider.open > .reveal, .hider:not(.open) > :not(.reveal) {
display: none !important;
}
.hider:not(.open) > :not(.reveal) {
display: none !important; display: none !important;
} }

View File

@ -48,7 +48,7 @@
toggleHider(false); toggleHider(false);
let dnd = { let dnd = {
dragstart(ev) { dragstart(ev) {
let d = ev.target; let d = ev.target;
if (hider.querySelectorAll(".icon").length) { if (hider.querySelectorAll(".icon").length) {
toggleHider(true); toggleHider(true);
@ -58,12 +58,25 @@
ev.preventDefault(); ev.preventDefault();
return; return;
} }
// work-around for Firefox unable to drag buttons, https://bugzilla.mozilla.org/show_bug.cgi?id=568313
let placeHolder = document.createElement("a");
for (let attr of d.attributes) {
placeHolder.setAttribute(attr.name, attr.value);
}
placeHolder.style.position = "absolute";
placeHolder.style.top = "-2000px";
d.parentNode.appendChild(placeHolder);
setTimeout(() => placeHolder.remove(), 0);
d.style.opacity = ".5"; d.style.opacity = ".5";
d.style.filter = "none"; d.style.filter = "none";
let dt = ev.dataTransfer; let dt = ev.dataTransfer;
dt.setData("text/plain", d.id); dt.setData("text/plain", d.id);
dt.dropEffect = "move"; dt.dropEffect = "move";
dt.setDragImage(d, d.offsetWidth / 2, d.offsetHeight / 2);
dt.setDragImage(placeHolder, d.offsetWidth / 2, d.offsetHeight / 2);
toggleHider(true); toggleHider(true);
this.draggedElement = d; this.draggedElement = d;
}, },
@ -82,10 +95,9 @@
}, },
drop(ev) { drop(ev) {
let t = ev.target; let t = ev.target;
let d = ev.dataTransfer ? let d = this.draggedElement;
document.getElementById(ev.dataTransfer.getData("text/plain"))
: this.draggedElement;
if (!d) return; if (!d) return;
switch(t) { switch(t) {
case hider: case hider:
t.appendChild(d); t.appendChild(d);
@ -138,6 +150,7 @@
} }
for (let draggable of document.querySelectorAll("#top .icon")) { for (let draggable of document.querySelectorAll("#top .icon")) {
draggable.innerHTML = "<div></div>";
draggable.setAttribute("draggable", "true"); draggable.setAttribute("draggable", "true");
} }
} }