-
Notifications
You must be signed in to change notification settings - Fork 38
/
button.js
34 lines (32 loc) · 1.16 KB
/
button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const Button = {
__mouseDown(event) {
var btn = event.target.closest("*:not(btn-group) > .btn-system:not(.active)");
if (btn) {
// Clone button for sandboxing
var sandboxBtn = btn.cloneNode(true);
sandboxBtn.classList.add("sandbox");
// Append the sanbox button to the DOM
document.body.appendChild(sandboxBtn);
// Get informations from sandbox button
var sandboxBoundings = sandboxBtn.getBoundingClientRect();
// Remove sanbox button from DOM
document.body.removeChild(sandboxBtn);
// Round up to 4 decimal numbers because more are not supported by CSS
btn.style.width = sandboxBoundings.width + "px";
// Add this width as stamp
btn.__photonModifiedWidth = btn.style.width;
}
},
__mouseUp(event) {
var btns = document.getElementsByTagName("button");
for (let btn of btns) {
if (btn.__photonModifiedWidth === btn.style.width) {
btn.style.removeProperty("width");
delete btn.__photonModifiedWidth;
}
}
}
};
window.addEventListener("mousedown", Button.__mouseDown);
window.addEventListener("mouseup", Button.__mouseUp);
module.exports = Button;