1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// https://www.val.town/embed/liamdanielduffy.selfEmbedded
export async function selfEmbeddedNoFramework(
req: express.Request,
res: express.Response,
) {
res.set("Content-Type", "text/html");
res.send(`
<!DOCTYPE html>
<html>
<head>
<title>Resizable and Draggable Iframes</title>
<style>
#canvas {
position: relative;
width: 800px;
height: 600px;
border: 1px solid black;
}
.iframe-box {
position: absolute;
overflow: auto;
background-color: #f0f0f0;
border: 1px solid gray;
}
.drag-handle {
position: absolute;
width: 10px;
height: 10px;
background-color: #000;
cursor: pointer;
}
.top-handle {
top: -5px;
left: 50%;
transform: translateX(-50%);
}
.bottom-right-handle {
bottom: -5px;
right: -5px;
}
</style>
</head>
<body>
<div id="canvas">
<div class="iframe-box" style="top: 100px; left: 100px; width: 200px; height: 150px;">
<div class="drag-handle top-handle"></div>
<div class="drag-handle bottom-right-handle"></div>
<iframe src="https://www.val.town/embed/liamdanielduffy.selfEmbedded"></iframe>
</div>
<div class="iframe-box" style="top: 300px; left: 300px; width: 250px; height: 200px;">
<div class="drag-handle top-handle"></div>
<div class="drag-handle bottom-right-handle"></div>
<iframe src="https://www.val.town/embed/liamdanielduffy.selfEmbedded"></iframe>
</div>
</div>
<script>
const iframeBoxes = document.querySelectorAll('.iframe-box');
iframeBoxes.forEach((iframeBox) => {
makeResizable(iframeBox);
makeDraggable(iframeBox);
});
function makeResizable(element) {
const resizer = document.createElement('div');
resizer.className = 'drag-handle bottom-right-handle';
element.appendChild(resizer);
let startX, startY, startWidth, startHeight, startIframeWidth, startIframeHeight;
resizer.addEventListener('mousedown', initResize, false);
function initResize(e) {
startX = e.clientX;
startY = e.clientY;
startWidth = parseInt(document.defaultView.getComputedStyle(element).width, 10);
startHeight = parseInt(document.defaultView.getComputedStyle(element).height, 10);
startIframeWidth = parseInt(element.querySelector('iframe').style.width, 10);
startIframeHeight = parseInt(element.querySelector('iframe').style.height, 10);
document.documentElement.addEventListener('mousemove', resize, false);
document.documentElement.addEventListener('mouseup', stopResize, false);
}
function resize(e) {
const width = startWidth + e.clientX - startX;
const height = startHeight + e.clientY - startY;
element.style.width = width + 'px';
element.style.height = height + 'px';
element.querySelector('iframe').style.width = startIframeWidth + (width - startWidth) + 'px';
element.querySelector('iframe').style.height = startIframeHeight + (height - startHeight) + 'px';
}
function stopResize() {
document.documentElement.removeEventListener('mousemove', resize, false);
document.documentElement.removeEventListener('mouseup', stopResize, false);
}
}
function makeDraggable(element) {