Skip to content

Commit 03ac72a

Browse files
committed
add pretty resize ui
1 parent 917be39 commit 03ac72a

File tree

1 file changed

+63
-30
lines changed

1 file changed

+63
-30
lines changed

resize/index.html

Lines changed: 63 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,56 @@
22
<html>
33
<head>
44
<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+
}
512
.resize-drag {
613
width: 1280px;
7-
height: 720px;
8-
padding: 20px;
914
margin: 1rem;
10-
background-color: #29e;
11-
color: white;
1215
font-size: 20px;
1316
font-family: sans-serif;
14-
15-
touch-action: none;
17+
background-color: rgb(0, 127, 239);
1618

1719
/* This makes things *much* easier */
1820
box-sizing: border-box;
1921
}
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+
}
2040
</style>
2141
</head>
2242
<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>
2555
<script src="https://unpkg.com/interactjs/dist/interact.min.js"></script>
2656
<script type="module">
2757
import Hyperbeam from 'https://unpkg.com/@hyperbeam/web@latest/dist/index.js'
@@ -36,31 +66,27 @@
3666
target.setAttribute('data-y', y);
3767
}
3868

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");
4672
interact('.resize-drag')
4773
.resizable({
4874
edges: { left: true, right: true, bottom: true, top: true },
4975
listeners: {
5076
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);
5480

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';
5783

58-
x += event.deltaRect.left
59-
y += event.deltaRect.top
84+
x += event.deltaRect.left;
85+
y += event.deltaRect.top;
6086

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);
6490
}
6591
},
6692
modifiers: [
@@ -76,11 +102,18 @@
76102
});
77103
}
78104

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();
84117
</script>
85118
</div>
86119
</body>

0 commit comments

Comments
 (0)