More deterministic DnD placeholder creation.

This commit is contained in:
hackademix 2022-02-28 09:30:35 +01:00
parent 4099f548be
commit e225332eee
1 changed files with 12 additions and 7 deletions

View File

@ -69,13 +69,18 @@
ev.preventDefault();
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 button.attributes) {
placeHolder.setAttribute(attr.name, attr.value);
}
placeHolder.style.position = "absolute";
placeHolder.style.top = "-2000px";
let placeHolder = document.createElement("div");
let {style} = placeHolder;
style.backgroundImage = getComputedStyle(button).backgroundImage;
style.backgroundSize = "contain";
let width = button.offsetWidth * 1.2;
let height = button.offsetHeight * 1.2;
style.width =`${width}px`;
style.height = `${height}px`
style.position = "absolute";
style.top = "-2000px";
toolbar.appendChild(placeHolder);
setTimeout(() => placeHolder.remove(), 0);
@ -83,7 +88,7 @@
dt.setData("text/plain", button.id);
dt.dropEffect = "move";
dt.setDragImage(placeHolder, button.offsetWidth / 2, button.offsetHeight / 2);
dt.setDragImage(placeHolder, width / 2, height / 2);
toggleHider(true);
this.draggedElement = ev.target; // the draggable wrapper around the button