2022-11-22 16:24:55 -06:00
|
|
|
function makeDraggable(element) {
|
2022-11-21 05:24:35 -06:00
|
|
|
let dragging = false;
|
|
|
|
let offset = {x: 0, y: 0};
|
|
|
|
|
2022-11-30 15:44:51 -06:00
|
|
|
const margin = 10;
|
|
|
|
|
|
|
|
const fixPos = () => {
|
|
|
|
const dbb = element.getBoundingClientRect();
|
|
|
|
if (dbb.left < margin) element.style.left = margin + "px";
|
|
|
|
else if (dbb.right > window.innerWidth - margin)
|
|
|
|
element.style.left =
|
|
|
|
dbb.left + (window.innerWidth - margin - dbb.right) + "px";
|
|
|
|
|
|
|
|
if (dbb.top < margin) element.style.top = margin + "px";
|
|
|
|
else if (dbb.bottom > window.innerHeight - margin)
|
|
|
|
element.style.top =
|
|
|
|
dbb.top + (window.innerHeight - margin - dbb.bottom) + "px";
|
|
|
|
};
|
2022-11-21 05:24:35 -06:00
|
|
|
|
2022-11-28 16:48:42 -06:00
|
|
|
mouse.listen.window.btn.left.onpaintstart.on((evn) => {
|
2022-11-21 05:24:35 -06:00
|
|
|
if (
|
|
|
|
element.contains(evn.target) &&
|
|
|
|
evn.target.classList.contains("draggable")
|
|
|
|
) {
|
|
|
|
const bb = element.getBoundingClientRect();
|
|
|
|
offset.x = evn.x - bb.x;
|
|
|
|
offset.y = evn.y - bb.y;
|
|
|
|
dragging = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-11-28 16:48:42 -06:00
|
|
|
mouse.listen.window.btn.left.onpaint.on((evn) => {
|
2022-11-21 05:24:35 -06:00
|
|
|
if (dragging) {
|
2022-11-30 15:44:51 -06:00
|
|
|
element.style.right = null;
|
|
|
|
element.style.bottom = null;
|
2022-11-21 05:24:35 -06:00
|
|
|
element.style.top = evn.y - offset.y + "px";
|
|
|
|
element.style.left = evn.x - offset.x + "px";
|
2022-11-30 15:44:51 -06:00
|
|
|
|
|
|
|
fixPos();
|
2022-11-21 05:24:35 -06:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-11-28 16:48:42 -06:00
|
|
|
mouse.listen.window.btn.left.onpaintend.on((evn) => {
|
2022-11-21 05:24:35 -06:00
|
|
|
dragging = false;
|
|
|
|
});
|
2022-11-30 15:44:51 -06:00
|
|
|
|
|
|
|
window.addEventListener("resize", () => {
|
|
|
|
fixPos();
|
|
|
|
});
|
2022-11-21 05:24:35 -06:00
|
|
|
}
|
|
|
|
|
2022-11-22 16:24:55 -06:00
|
|
|
document.querySelectorAll(".floating-window").forEach((w) => {
|
|
|
|
makeDraggable(w);
|
|
|
|
});
|
2022-11-21 05:24:35 -06:00
|
|
|
|
2022-11-19 15:48:12 -06:00
|
|
|
var coll = document.getElementsByClassName("collapsible");
|
|
|
|
for (var i = 0; i < coll.length; i++) {
|
2022-11-25 17:27:44 -06:00
|
|
|
let active = false;
|
2022-11-20 17:10:03 -06:00
|
|
|
coll[i].addEventListener("click", function () {
|
|
|
|
var content = this.nextElementSibling;
|
2022-11-25 17:27:44 -06:00
|
|
|
|
|
|
|
if (!active) {
|
|
|
|
this.classList.add("active");
|
|
|
|
content.classList.add("active");
|
|
|
|
} else {
|
|
|
|
this.classList.remove("active");
|
|
|
|
content.classList.remove("active");
|
|
|
|
}
|
|
|
|
|
|
|
|
const observer = new ResizeObserver(() => {
|
|
|
|
if (active) content.style.maxHeight = content.scrollHeight + "px";
|
|
|
|
});
|
|
|
|
|
|
|
|
Array.from(content.children).forEach((child) => {
|
|
|
|
observer.observe(child);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (active) {
|
2022-11-20 17:10:03 -06:00
|
|
|
content.style.maxHeight = null;
|
2022-11-25 17:27:44 -06:00
|
|
|
active = false;
|
2022-11-20 17:10:03 -06:00
|
|
|
} else {
|
|
|
|
content.style.maxHeight = content.scrollHeight + "px";
|
2022-11-25 17:27:44 -06:00
|
|
|
active = true;
|
2022-11-20 17:10:03 -06:00
|
|
|
}
|
|
|
|
});
|
2022-11-20 15:39:24 -06:00
|
|
|
}
|
2022-11-23 22:53:14 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Slider Inputs
|
|
|
|
*/
|
|
|
|
function createSlider(name, wrapper, options = {}) {
|
|
|
|
defaultOpt(options, {
|
|
|
|
valuecb: null,
|
|
|
|
min: 0,
|
|
|
|
max: 1,
|
|
|
|
step: 0.1,
|
|
|
|
defaultValue: 0.7,
|
|
|
|
});
|
|
|
|
|
|
|
|
let value = options.defaultValue;
|
|
|
|
|
|
|
|
// Use phantom range element for rounding
|
|
|
|
const phantomRange = document.createElement("input");
|
|
|
|
phantomRange.type = "range";
|
|
|
|
phantomRange.min = options.min;
|
|
|
|
phantomRange.max = options.max;
|
|
|
|
phantomRange.step = options.step;
|
|
|
|
|
|
|
|
// Build slider element
|
|
|
|
const underEl = document.createElement("div");
|
|
|
|
underEl.classList.add("under");
|
|
|
|
const textEl = document.createElement("input");
|
|
|
|
textEl.type = "text";
|
|
|
|
textEl.classList.add("text");
|
|
|
|
|
|
|
|
const overEl = document.createElement("div");
|
|
|
|
overEl.classList.add("over");
|
|
|
|
|
|
|
|
wrapper.classList.add("slider-wrapper");
|
|
|
|
wrapper.appendChild(underEl);
|
|
|
|
wrapper.appendChild(textEl);
|
|
|
|
wrapper.appendChild(overEl);
|
|
|
|
|
|
|
|
const bar = document.createElement("div");
|
|
|
|
bar.classList.add("slider-bar");
|
|
|
|
underEl.appendChild(bar);
|
|
|
|
underEl.appendChild(document.createElement("div"));
|
|
|
|
|
|
|
|
// Set value
|
|
|
|
const setValue = (val) => {
|
|
|
|
phantomRange.value = val;
|
|
|
|
value = parseFloat(phantomRange.value);
|
|
|
|
bar.style.width = `${
|
2022-11-24 08:54:30 -06:00
|
|
|
100 * ((value - options.min) / (options.max - options.min))
|
|
|
|
}%`;
|
2022-11-23 22:53:14 -06:00
|
|
|
textEl.value = `${name}: ${value}`;
|
|
|
|
options.valuecb && options.valuecb(value);
|
|
|
|
};
|
|
|
|
|
|
|
|
setValue(options.defaultValue);
|
|
|
|
|
|
|
|
// Events
|
|
|
|
textEl.addEventListener("blur", () => {
|
|
|
|
overEl.style.pointerEvents = "auto";
|
|
|
|
textEl.value = `${name}: ${value}`;
|
|
|
|
});
|
|
|
|
textEl.addEventListener("focus", () => {
|
2022-11-24 09:30:13 -06:00
|
|
|
overEl.style.pointerEvents = "none";
|
2022-11-23 22:53:14 -06:00
|
|
|
textEl.value = value;
|
|
|
|
});
|
|
|
|
|
|
|
|
textEl.addEventListener("change", () => {
|
|
|
|
try {
|
|
|
|
if (Number.isNaN(parseFloat(textEl.value))) setValue(value);
|
|
|
|
else setValue(parseFloat(textEl.value));
|
|
|
|
} catch (e) {}
|
|
|
|
});
|
|
|
|
|
|
|
|
keyboard.listen.onkeyclick.on((evn) => {
|
|
|
|
if (evn.target === textEl && evn.code === "Enter") {
|
|
|
|
textEl.blur();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-11-28 16:48:42 -06:00
|
|
|
mouse.listen.window.btn.left.onclick.on((evn) => {
|
2022-11-23 22:53:14 -06:00
|
|
|
if (evn.target === overEl) {
|
|
|
|
textEl.select();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-11-28 16:48:42 -06:00
|
|
|
mouse.listen.window.btn.left.ondrag.on((evn) => {
|
2022-11-29 14:55:25 -06:00
|
|
|
if (evn.initialTarget === overEl) {
|
2022-11-23 22:53:14 -06:00
|
|
|
setValue(
|
|
|
|
Math.max(
|
|
|
|
options.min,
|
|
|
|
Math.min(
|
|
|
|
options.max,
|
|
|
|
(evn.evn.layerX / wrapper.offsetWidth) *
|
|
|
|
(options.max - options.min) +
|
|
|
|
options.min
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
set value(val) {
|
|
|
|
setValue(val);
|
|
|
|
},
|
|
|
|
get value() {
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|