|
10 | 10 | background-size: 6em 6em; |
11 | 11 | } |
12 | 12 | .resize-drag { |
13 | | - width: 1280px; |
14 | 13 | margin: 1rem; |
15 | 14 | font-size: 20px; |
16 | 15 | font-family: sans-serif; |
17 | 16 | background-color: rgb(0, 127, 239); |
18 | | - |
19 | | - /* This makes things *much* easier */ |
| 17 | + display: inline-block; |
20 | 18 | box-sizing: border-box; |
| 19 | + position: relative; |
| 20 | + } |
| 21 | + #cloudComputerDiv { |
| 22 | + width: 100%; |
| 23 | + height: 100%; |
21 | 24 | } |
22 | 25 | .bar { |
| 26 | + position: absolute; |
| 27 | + top: 100%; |
23 | 28 | background-color: rgb(0, 127, 239); |
24 | 29 | height: 36px; |
25 | 30 | width: 100%; |
| 31 | + text-align: center; |
26 | 32 | } |
27 | | - .hidden { |
| 33 | + .lock.hidden { |
28 | 34 | display: none; |
29 | 35 | } |
30 | 36 | .lock { |
31 | 37 | border: none; |
32 | 38 | background: none; |
33 | 39 | cursor: pointer; |
34 | | - width: 100%; |
| 40 | + display: inline-block; |
35 | 41 | margin: 4px auto; |
36 | 42 | } |
37 | 43 | .lock path { |
|
66 | 72 | target.setAttribute('data-y', y); |
67 | 73 | } |
68 | 74 |
|
69 | | - function enableInteractives() { |
| 75 | + function enableInteractives(hb) { |
70 | 76 | lock.classList.remove("hidden"); |
71 | 77 | unlock.classList.add("hidden"); |
72 | 78 | interact('.resize-drag') |
|
78 | 84 | let x = (parseFloat(target.getAttribute('data-x')) || 0); |
79 | 85 | let y = (parseFloat(target.getAttribute('data-y')) || 0); |
80 | 86 |
|
81 | | - target.style.width = event.rect.width + 'px'; |
82 | | - target.style.height = event.rect.height + 'px'; |
| 87 | + let width = Math.floor(event.rect.width) |
| 88 | + let height = Math.floor(event.rect.height) |
| 89 | + if (width * height <= hb.initialWidth * hb.initialHeight) { |
| 90 | + hb.resize(width, height) |
| 91 | + } |
83 | 92 |
|
84 | 93 | x += event.deltaRect.left; |
85 | 94 | y += event.deltaRect.top; |
|
108 | 117 | interact('.resize-drag').unset(); |
109 | 118 | } |
110 | 119 |
|
111 | | - lock.addEventListener('click', disableInteractives); |
112 | | - unlock.addEventListener('click', enableInteractives); |
113 | 120 | const resp = await fetch('/computer'); |
114 | 121 | const data = await resp.json(); |
115 | 122 | const hb = await Hyperbeam(cloudComputerDiv, data.embed_url); |
116 | | - enableInteractives(); |
| 123 | + lock.addEventListener('click', disableInteractives); |
| 124 | + unlock.addEventListener('click', () => enableInteractives(hb)); |
| 125 | + enableInteractives(hb); |
117 | 126 | </script> |
118 | 127 | </div> |
119 | 128 | </body> |
|
0 commit comments