Make disabled buttons draggable and hidden enabled buttons interactive when the "graveyard" is open.
This commit is contained in:
parent
e6e926622e
commit
f4cd8bf63d
|
@ -194,6 +194,10 @@ body {
|
||||||
color: transparent;
|
color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#top .icon.drag, #top .drag > .icon {
|
||||||
|
filter: none !important;
|
||||||
|
opacity: 0.6 !important;
|
||||||
|
}
|
||||||
|
|
||||||
#revoke-temp {
|
#revoke-temp {
|
||||||
background-image: url(/img/ui-revoke-temp64.png) !important;
|
background-image: url(/img/ui-revoke-temp64.png) !important;
|
||||||
|
|
|
@ -120,7 +120,7 @@ addEventListener("unload", e => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let b of document.querySelectorAll("#top > .icon")) {
|
for (let b of document.querySelectorAll("#top .icon")) {
|
||||||
b.tabIndex = 0;
|
b.tabIndex = 0;
|
||||||
if (b.id in handlers) {
|
if (b.id in handlers) {
|
||||||
let h = handlers[b.id];
|
let h = handlers[b.id];
|
||||||
|
|
|
@ -36,7 +36,19 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleHider(b) {
|
|
||||||
|
let makeDraggable = b => {
|
||||||
|
// work-around for dragging disabled buttons
|
||||||
|
let wrapper = document.createElement("div");
|
||||||
|
b.replaceWith(wrapper);
|
||||||
|
// work-around for dragging empty (padding only) elements
|
||||||
|
b.innerHTML = "<div></div>";
|
||||||
|
wrapper.appendChild(b);
|
||||||
|
b = wrapper;
|
||||||
|
b.setAttribute("draggable", "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
let toggleHider = b => {
|
||||||
let cl = hider.classList;
|
let cl = hider.classList;
|
||||||
cl.toggle("open", b);
|
cl.toggle("open", b);
|
||||||
cl.toggle("empty", !hider.querySelector(".icon"));
|
cl.toggle("empty", !hider.querySelector(".icon"));
|
||||||
|
@ -49,41 +61,36 @@
|
||||||
|
|
||||||
let dnd = {
|
let dnd = {
|
||||||
dragstart(ev) {
|
dragstart(ev) {
|
||||||
let d = ev.target;
|
|
||||||
if (hider.querySelectorAll(".icon").length) {
|
if (hider.querySelectorAll(".icon").length) {
|
||||||
toggleHider(true);
|
toggleHider(true);
|
||||||
}
|
}
|
||||||
|
let button = ev.target.querySelector(".icon");
|
||||||
if (!d.classList.contains("icon")) {
|
if (!button) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// work-around for Firefox unable to drag buttons, https://bugzilla.mozilla.org/show_bug.cgi?id=568313
|
// work-around for Firefox unable to drag buttons, https://bugzilla.mozilla.org/show_bug.cgi?id=568313
|
||||||
let placeHolder = document.createElement("a");
|
let placeHolder = document.createElement("a");
|
||||||
for (let attr of d.attributes) {
|
for (let attr of button.attributes) {
|
||||||
placeHolder.setAttribute(attr.name, attr.value);
|
placeHolder.setAttribute(attr.name, attr.value);
|
||||||
}
|
}
|
||||||
placeHolder.style.position = "absolute";
|
placeHolder.style.position = "absolute";
|
||||||
placeHolder.style.top = "-2000px";
|
placeHolder.style.top = "-2000px";
|
||||||
d.parentNode.appendChild(placeHolder);
|
toolbar.appendChild(placeHolder);
|
||||||
setTimeout(() => placeHolder.remove(), 0);
|
setTimeout(() => placeHolder.remove(), 0);
|
||||||
|
|
||||||
d.style.opacity = ".5";
|
|
||||||
d.style.filter = "none";
|
|
||||||
|
|
||||||
let dt = ev.dataTransfer;
|
let dt = ev.dataTransfer;
|
||||||
dt.setData("text/plain", d.id);
|
dt.setData("text/plain", button.id);
|
||||||
dt.dropEffect = "move";
|
dt.dropEffect = "move";
|
||||||
|
|
||||||
dt.setDragImage(placeHolder, d.offsetWidth / 2, d.offsetHeight / 2);
|
dt.setDragImage(placeHolder, button.offsetWidth / 2, button.offsetHeight / 2);
|
||||||
|
|
||||||
toggleHider(true);
|
toggleHider(true);
|
||||||
this.draggedElement = d;
|
this.draggedElement = ev.target; // the draggable wrapper around the button
|
||||||
|
this.draggedElement.classList.add("drag");
|
||||||
},
|
},
|
||||||
dragend(ev) {
|
dragend(ev) {
|
||||||
let d = ev.target;
|
this.draggedElement.classList.remove("drag");
|
||||||
d.style.opacity = "";
|
|
||||||
d.style.filter = "";
|
|
||||||
this.draggedElement = null;
|
this.draggedElement = null;
|
||||||
},
|
},
|
||||||
dragover(ev) {
|
dragover(ev) {
|
||||||
|
@ -116,7 +123,7 @@
|
||||||
|
|
||||||
let left = [], right = [];
|
let left = [], right = [];
|
||||||
let side = left;
|
let side = left;
|
||||||
for (let el of document.querySelectorAll("#top > .icon, #top > .spacer")) {
|
for (let el of toolbar.querySelectorAll(":scope > .spacer, :scope > [draggable] > .icon")) {
|
||||||
if (el === spacer) {
|
if (el === spacer) {
|
||||||
side = right;
|
side = right;
|
||||||
} else {
|
} else {
|
||||||
|
@ -125,7 +132,7 @@
|
||||||
}
|
}
|
||||||
UI.local.toolbarLayout = {
|
UI.local.toolbarLayout = {
|
||||||
left, right,
|
left, right,
|
||||||
hidden: Array.from(document.querySelectorAll("#top > .hider > .icon")).map(el => el.id),
|
hidden: Array.from(toolbar.querySelectorAll(".hider .icon")).map(el => el.id),
|
||||||
};
|
};
|
||||||
|
|
||||||
debug("%o", UI.local);
|
debug("%o", UI.local);
|
||||||
|
@ -134,10 +141,7 @@
|
||||||
|
|
||||||
click(ev) {
|
click(ev) {
|
||||||
let el = ev.target;
|
let el = ev.target;
|
||||||
if (el.parentNode === hider && el.classList.contains("icon")) {
|
if (el === spacer || el.classList.contains("reveal")) {
|
||||||
ev.preventDefault();
|
|
||||||
ev.stopPropagation();
|
|
||||||
} else if (el === spacer || el.classList.contains("reveal")) {
|
|
||||||
toggleHider(true);
|
toggleHider(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,8 +153,7 @@
|
||||||
toolbar.addEventListener(action, handler, true);
|
toolbar.addEventListener(action, handler, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let draggable of document.querySelectorAll("#top .icon")) {
|
for (let b of toolbar.querySelectorAll(".icon")) {
|
||||||
draggable.innerHTML = "<div></div>";
|
makeDraggable(b);
|
||||||
draggable.setAttribute("draggable", "true");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue