|
2 | 2 | <html> |
3 | 3 | <head> |
4 | 4 | <style> |
| 5 | + body { |
| 6 | + margin: 0; |
| 7 | + padding: 0; |
| 8 | + width: 100%; |
| 9 | + background-image: linear-gradient(rgba(0, 127, 239, .3) .1em, transparent .1em), linear-gradient(90deg, rgba(0, 127, 239, .3) .1em, transparent .1em); |
| 10 | + background-size: 6em 6em; |
| 11 | + } |
5 | 12 | .resize-drag { |
6 | 13 | width: 1280px; |
7 | | - height: 720px; |
8 | | - padding: 20px; |
9 | 14 | margin: 1rem; |
10 | | - background-color: #29e; |
11 | | - color: white; |
12 | 15 | font-size: 20px; |
13 | 16 | font-family: sans-serif; |
14 | | - |
15 | | - touch-action: none; |
| 17 | + background-color: rgb(0, 127, 239); |
16 | 18 |
|
17 | 19 | /* This makes things *much* easier */ |
18 | 20 | box-sizing: border-box; |
19 | 21 | } |
| 22 | + .bar { |
| 23 | + background-color: rgb(0, 127, 239); |
| 24 | + height: 36px; |
| 25 | + width: 100%; |
| 26 | + } |
| 27 | + .hidden { |
| 28 | + display: none; |
| 29 | + } |
| 30 | + .lock { |
| 31 | + border: none; |
| 32 | + background: none; |
| 33 | + cursor: pointer; |
| 34 | + width: 100%; |
| 35 | + margin: 4px auto; |
| 36 | + } |
| 37 | + .lock path { |
| 38 | + fill: #fff; |
| 39 | + } |
20 | 40 | </style> |
21 | 41 | </head> |
22 | 42 | <body> |
23 | | - <button id="lock">Unlock</button> |
24 | | - <div id="cloudComputerDiv" class="resize-drag">Resize from any edge or corner</div> |
| 43 | + <div class="resize-drag"> |
| 44 | + <div id="cloudComputerDiv"></div> |
| 45 | + <div class="bar"> |
| 46 | + <button id="unlock" class="lock"> |
| 47 | + <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12,17A2,2 0 0,0 14,15C14,13.89 13.1,13 12,13A2,2 0 0,0 10,15A2,2 0 0,0 12,17M18,8A2,2 0 0,1 20,10V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V10C4,8.89 4.9,8 6,8H7V6A5,5 0 0,1 12,1A5,5 0 0,1 17,6V8H18M12,3A3,3 0 0,0 9,6V8H15V6A3,3 0 0,0 12,3Z" /></svg> |
| 48 | + </button> |
| 49 | + <button id="lock" class="lock hidden"> |
| 50 | + <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M18,8A2,2 0 0,1 20,10V20A2,2 0 0,1 18,22H6C4.89,22 4,21.1 4,20V10A2,2 0 0,1 6,8H15V6A3,3 0 0,0 12,3A3,3 0 0,0 9,6H7A5,5 0 0,1 12,1A5,5 0 0,1 17,6V8H18M12,17A2,2 0 0,0 14,15A2,2 0 0,0 12,13A2,2 0 0,0 10,15A2,2 0 0,0 12,17Z" /></svg> |
| 51 | + |
| 52 | + </button> |
| 53 | + </div> |
| 54 | + </div> |
25 | 55 | <script src="https://unpkg.com/interactjs/dist/interact.min.js"></script> |
26 | 56 | <script type="module"> |
27 | 57 | import Hyperbeam from 'https://unpkg.com/@hyperbeam/web@latest/dist/index.js' |
|
36 | 66 | target.setAttribute('data-y', y); |
37 | 67 | } |
38 | 68 |
|
39 | | - function toggleInteractives() { |
40 | | - if (lock.innerText === 'Lock') { |
41 | | - lock.innerText = 'Unlock' |
42 | | - interact('.resize-drag').unset() |
43 | | - return |
44 | | - } |
45 | | - lock.innerText = 'Lock' |
| 69 | + function enableInteractives() { |
| 70 | + lock.classList.remove("hidden"); |
| 71 | + unlock.classList.add("hidden"); |
46 | 72 | interact('.resize-drag') |
47 | 73 | .resizable({ |
48 | 74 | edges: { left: true, right: true, bottom: true, top: true }, |
49 | 75 | listeners: { |
50 | 76 | move (event) { |
51 | | - const target = event.target |
52 | | - let x = (parseFloat(target.getAttribute('data-x')) || 0) |
53 | | - let y = (parseFloat(target.getAttribute('data-y')) || 0) |
| 77 | + const target = event.target; |
| 78 | + let x = (parseFloat(target.getAttribute('data-x')) || 0); |
| 79 | + let y = (parseFloat(target.getAttribute('data-y')) || 0); |
54 | 80 |
|
55 | | - target.style.width = event.rect.width + 'px' |
56 | | - target.style.height = event.rect.height + 'px' |
| 81 | + target.style.width = event.rect.width + 'px'; |
| 82 | + target.style.height = event.rect.height + 'px'; |
57 | 83 |
|
58 | | - x += event.deltaRect.left |
59 | | - y += event.deltaRect.top |
| 84 | + x += event.deltaRect.left; |
| 85 | + y += event.deltaRect.top; |
60 | 86 |
|
61 | | - target.style.transform = 'translate(' + x + 'px,' + y + 'px)' |
62 | | - target.setAttribute('data-x', x) |
63 | | - target.setAttribute('data-y', y) |
| 87 | + target.style.transform = `translate(${x}px, ${y}px)`; |
| 88 | + target.setAttribute('data-x', x); |
| 89 | + target.setAttribute('data-y', y); |
64 | 90 | } |
65 | 91 | }, |
66 | 92 | modifiers: [ |
|
76 | 102 | }); |
77 | 103 | } |
78 | 104 |
|
79 | | - lock.addEventListener('click', toggleInteractives) |
80 | | - const resp = await fetch('/computer') |
81 | | - const data = await resp.json() |
82 | | - const hb = await Hyperbeam(cloudComputerDiv, data.embed_url) |
83 | | - toggleInteractives() |
| 105 | + function disableInteractives() { |
| 106 | + lock.classList.add("hidden"); |
| 107 | + unlock.classList.remove("hidden"); |
| 108 | + interact('.resize-drag').unset(); |
| 109 | + } |
| 110 | + |
| 111 | + lock.addEventListener('click', disableInteractives); |
| 112 | + unlock.addEventListener('click', enableInteractives); |
| 113 | + const resp = await fetch('/computer'); |
| 114 | + const data = await resp.json(); |
| 115 | + const hb = await Hyperbeam(cloudComputerDiv, data.embed_url); |
| 116 | + enableInteractives(); |
84 | 117 | </script> |
85 | 118 | </div> |
86 | 119 | </body> |
|
0 commit comments