|
1 | 1 | // This injects a box into the page that moves with the mouse;
|
2 | 2 | // Useful for debugging
|
3 | 3 | (function () {
|
4 |
| - const box = document.createElement('div'); |
5 |
| - box.classList.add('mouse-helper'); |
6 |
| - const styleElement = document.createElement('style'); |
7 |
| - styleElement.innerHTML = ` |
| 4 | + const box = document.createElement('div'); |
| 5 | + box.classList.add('mouse-helper'); |
| 6 | + const styleElement = document.createElement('style'); |
| 7 | + styleElement.innerHTML = ` |
8 | 8 | .mouse-helper {
|
9 | 9 | pointer-events: none;
|
10 | 10 | position: absolute;
|
|
40 | 40 | border-color: rgba(0,255,0,0.9);
|
41 | 41 | }
|
42 | 42 | `;
|
43 |
| - document.head.appendChild(styleElement); |
44 |
| - document.body.appendChild(box); |
45 |
| - document.addEventListener( |
46 |
| - 'mousemove', |
47 |
| - (event) => { |
48 |
| - box.style.left = event.pageX + 'px'; |
49 |
| - box.style.top = event.pageY + 'px'; |
50 |
| - updateButtons(event.buttons); |
51 |
| - }, |
52 |
| - true |
53 |
| - ); |
54 |
| - document.addEventListener( |
55 |
| - 'mousedown', |
56 |
| - (event) => { |
57 |
| - updateButtons(event.buttons); |
58 |
| - box.classList.add('button-' + event.which); |
59 |
| - }, |
60 |
| - true |
61 |
| - ); |
62 |
| - document.addEventListener( |
63 |
| - 'mouseup', |
64 |
| - (event) => { |
65 |
| - updateButtons(event.buttons); |
66 |
| - box.classList.remove('button-' + event.which); |
67 |
| - }, |
68 |
| - true |
69 |
| - ); |
70 |
| - function updateButtons(buttons) { |
71 |
| - for (let i = 0; i < 5; i++) |
72 |
| - box.classList.toggle('button-' + i, buttons & (1 << i)); |
73 |
| - } |
| 43 | + document.head.appendChild(styleElement); |
| 44 | + document.body.appendChild(box); |
| 45 | + document.addEventListener( |
| 46 | + 'mousemove', |
| 47 | + (event) => { |
| 48 | + box.style.left = event.pageX + 'px'; |
| 49 | + box.style.top = event.pageY + 'px'; |
| 50 | + updateButtons(event.buttons); |
| 51 | + }, |
| 52 | + true |
| 53 | + ); |
| 54 | + document.addEventListener( |
| 55 | + 'mousedown', |
| 56 | + (event) => { |
| 57 | + updateButtons(event.buttons); |
| 58 | + box.classList.add('button-' + event.which); |
| 59 | + }, |
| 60 | + true |
| 61 | + ); |
| 62 | + document.addEventListener( |
| 63 | + 'mouseup', |
| 64 | + (event) => { |
| 65 | + updateButtons(event.buttons); |
| 66 | + box.classList.remove('button-' + event.which); |
| 67 | + }, |
| 68 | + true |
| 69 | + ); |
| 70 | + function updateButtons(buttons) { |
| 71 | + for (let i = 0; i < 5; i++) |
| 72 | + {box.classList.toggle('button-' + i, buttons & (1 << i));} |
| 73 | + } |
74 | 74 | })();
|
0 commit comments