-
Notifications
You must be signed in to change notification settings - Fork 585
/
multi.html
144 lines (134 loc) · 4.9 KB
/
multi.html
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<html>
<head>
<title>MakeCode Multi Editor</title>
<style>
html, body {
overscroll-behavior: none;
}
iframe {
position: absolute;
width: calc(50% - 0.15rem);
height: 100%;
bottom: 0;
top: 0;
border: none;
}
#left {
left: 0;
right: calc(50% - 0.15rem);
}
#right {
right: 0;
left: calc(50% + 0.15rem);
}
#divider {
position: absolute;
width: 0.3rem;
cursor: col-resize;
height: 100%;
left: calc(50% - 0.15rem);
right: calc(50% + 0.15rem);
background: #bbb;
top: 0rem;
}
</style>
</head>
<body>
<iframe id="left" allow="usb;camera"></iframe>
<div id="divider"></div>
<iframe id="right" allow="usb;camera"></iframe>
<script>
(function () {
// This line gets patched up by the cloud
var pxtConfig = null;
var left = document.getElementById("left");
var right = document.getElementById("right");
var frames = [left, right]
var divider = document.getElementById("divider");
var localhost = window.location.hostname == "localhost";
var editor = (pxtConfig ? pxtConfig.relprefix : '/').replace(/-*$/, '');
var flags = "?nestededitorsim=1&editorlayout=ide&nosandbox=1&parentOrigin=" + encodeURIComponent(window.location.origin);
var ratio = .5;
var dividerWidth = 14;
function updateSrc(ifrm, hash) {
var h = hash ? "#" + hash : "";
console.log("hash: " + h)
if (localhost) {
ifrm.src = "/index.html" + flags + h;
} else {
ifrm.src = editor + flags + h;
}
}
function handleHash() {
var hashLeft = ""
var hashRight = ""
var route = (window.location.hash || "#");
var parts = route.replace(/^#/, '').split(':|:', 2);
updateSrc(left, parts[0]);
updateSrc(right, parts[1]);
window.history.replaceState('', '', '#')
}
function handleMessage(msg) {
var data = msg.data;
var source = msg.source;
if (!!data.broadcast) {
data.outer = true;
frames.filter(function (ifrm) {
return ifrm.contentWindow !== source;
})
.forEach(function (ifrm) {
ifrm.contentWindow.postMessage(data, window.location.origin)
});
}
}
function setWidths() {
var t = document.body.clientWidth;
var n = Math.floor(t * ratio);
var i = Math.max(t - n - dividerWidth, 4);
left.style.width = n + "px";
divider.style.left = n + "px";
divider.style.width = dividerWidth + "px";
right.style.left = n + dividerWidth + "px";
right.style.width = i + "px";
}
function startDrag() {
left.style.visibility = "hidden";
right.style.visibility = "hidden";
var n = divider.onmouseover;
var t = divider.onmouseout;
divider.onmouseover = null;
divider.onmouseout = null;
document.body.onmousemove = function (n) {
n || (n = window.event);
ratio = (n.clientX - dividerWidth / 2) / document.body.clientWidth;
ratio < .1 && (ratio = .1);
ratio > .9 && (ratio = .9);
setWidths();
}
document.body.onmouseup = function () {
document.body.onmousemove = null;
document.body.onmouseup = null;
left.style.visibility = "inherit";
right.style.visibility = "inherit";
divider.onmouseover = n;
divider.onmouseout = t;
}
}
window.onresize = setWidths;
window.onhashchange = handleHash;
window.onmessage = handleMessage;
divider.onmouseover = function () {
document.body.style.cursor = "w-resize";
divider.onmousedown = startDrag;
}
divider.onmouseout = function () {
document.body.style.cursor = "default";
divider.onmousedown = null;
}
setWidths();
handleHash();
})();
</script>
<!-- @include tracking.html -->
</body>
</html>