Skip to content

Commit 0983cb3

Browse files
philipjscottambyjkl
authored andcommitted
Finish resize example
1 parent 2a196c0 commit 0983cb3

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

resize/index.html

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,34 @@
1010
background-size: 6em 6em;
1111
}
1212
.resize-drag {
13-
width: 1280px;
1413
margin: 1rem;
1514
font-size: 20px;
1615
font-family: sans-serif;
1716
background-color: rgb(0, 127, 239);
18-
19-
/* This makes things *much* easier */
17+
display: inline-block;
2018
box-sizing: border-box;
19+
position: relative;
20+
}
21+
#cloudComputerDiv {
22+
width: 100%;
23+
height: 100%;
2124
}
2225
.bar {
26+
position: absolute;
27+
top: 100%;
2328
background-color: rgb(0, 127, 239);
2429
height: 36px;
2530
width: 100%;
31+
text-align: center;
2632
}
27-
.hidden {
33+
.lock.hidden {
2834
display: none;
2935
}
3036
.lock {
3137
border: none;
3238
background: none;
3339
cursor: pointer;
34-
width: 100%;
40+
display: inline-block;
3541
margin: 4px auto;
3642
}
3743
.lock path {
@@ -66,7 +72,7 @@
6672
target.setAttribute('data-y', y);
6773
}
6874

69-
function enableInteractives() {
75+
function enableInteractives(hb) {
7076
lock.classList.remove("hidden");
7177
unlock.classList.add("hidden");
7278
interact('.resize-drag')
@@ -78,8 +84,11 @@
7884
let x = (parseFloat(target.getAttribute('data-x')) || 0);
7985
let y = (parseFloat(target.getAttribute('data-y')) || 0);
8086

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+
}
8392

8493
x += event.deltaRect.left;
8594
y += event.deltaRect.top;
@@ -108,12 +117,12 @@
108117
interact('.resize-drag').unset();
109118
}
110119

111-
lock.addEventListener('click', disableInteractives);
112-
unlock.addEventListener('click', enableInteractives);
113120
const resp = await fetch('/computer');
114121
const data = await resp.json();
115122
const hb = await Hyperbeam(cloudComputerDiv, data.embed_url);
116-
enableInteractives();
123+
lock.addEventListener('click', disableInteractives);
124+
unlock.addEventListener('click', () => enableInteractives(hb));
125+
enableInteractives(hb);
117126
</script>
118127
</div>
119128
</body>

resize/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resize/server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ app.get('/computer', async (req, res) => {
1414
res.send(computer);
1515
return;
1616
}
17-
const resp = await axios.post('https://engine.hyperbeam.com/v0/vm', {}, {
17+
const resp = await axios.post('https://enginetest.hyperbeam.com/v0/vm', {region: "EU", timeout: {offline: 10}}, {
1818
headers: { 'Authorization': `Bearer ${process.env.HB_API_KEY}` }
1919
});
2020
computer = resp.data;
2121
res.send(computer);
2222
});
2323

24-
app.listen(8080, () => {
25-
console.log('Server start at http://localhost:8080');
24+
app.listen(8081, () => {
25+
console.log('Server start at http://localhost:8081');
2626
});

0 commit comments

Comments
 (0)