|
107 | 107 | }
|
108 | 108 |
|
109 | 109 | onMount(() => {
|
110 |
| - function on_iframe_load() { |
111 |
| - iframe.classList.add('loaded'); |
112 |
| - } |
113 | 110 | function destroy() {
|
114 |
| - iframe.removeEventListener('load', on_iframe_load); |
115 | 111 | if (adapter) {
|
116 | 112 | adapter.destroy();
|
117 | 113 | }
|
118 | 114 | }
|
119 | 115 |
|
120 | 116 | document.addEventListener('pagehide', destroy);
|
121 |
| - iframe.addEventListener('load', on_iframe_load); |
122 | 117 | return destroy;
|
123 | 118 | });
|
124 | 119 |
|
|
143 | 138 |
|
144 | 139 | if (adapter && path !== data.exercise.path) {
|
145 | 140 | path = data.exercise.path;
|
146 |
| - set_iframe_src(adapter.base + path); |
| 141 | + iframe.src = adapter.base + path; |
147 | 142 | }
|
148 | 143 |
|
149 | 144 | loading = false;
|
|
171 | 166 | status = s;
|
172 | 167 | });
|
173 | 168 |
|
174 |
| - set_iframe_src(adapter.base + path); |
| 169 | + iframe.src = adapter.base + path; |
175 | 170 | }
|
176 | 171 |
|
177 | 172 | await new Promise((fulfil, reject) => {
|
|
190 | 185 | if (!called && adapter) {
|
191 | 186 | // Updating the iframe too soon sometimes results in a blank screen,
|
192 | 187 | // so we try again after a short delay if we haven't heard back
|
193 |
| - set_iframe_src(adapter.base + path); |
| 188 | + iframe.src = adapter.base + path; |
194 | 189 | }
|
195 | 190 | }, 5000);
|
196 | 191 |
|
|
203 | 198 |
|
204 | 199 | if (reload_iframe) {
|
205 | 200 | await new Promise((fulfil) => setTimeout(fulfil, 200));
|
206 |
| - set_iframe_src(adapter.base + path); |
| 201 | + iframe.src = adapter.base + path; |
207 | 202 | }
|
208 | 203 |
|
209 | 204 | return adapter;
|
|
230 | 225 | clearTimeout(reload_timeout);
|
231 | 226 | reload_timeout = setTimeout(() => {
|
232 | 227 | if (adapter) {
|
233 |
| - set_iframe_src(adapter.base + path); |
| 228 | + iframe.src = adapter.base + path; |
234 | 229 | }
|
235 | 230 | }, 1000);
|
236 | 231 | }
|
|
287 | 282 |
|
288 | 283 | // we lost contact, refresh the page
|
289 | 284 | loading = true;
|
290 |
| - set_iframe_src(adapter.base + path); |
| 285 | + iframe.src = adapter.base + path; |
291 | 286 | loading = false;
|
292 | 287 | }, 1000);
|
293 | 288 | } else if (e.data.type === 'ping-pause') {
|
|
316 | 311 | return code.replace(/\s+/g, ' ').trim();
|
317 | 312 | }
|
318 | 313 |
|
319 |
| - /** @param {string} src */ |
320 |
| - function set_iframe_src(src) { |
321 |
| - // removing the iframe from the document allows us to |
322 |
| - // change the src without adding a history entry, which |
323 |
| - // would make back/forward traversal very annoying |
324 |
| - const parentNode = /** @type {HTMLElement} */ (iframe.parentNode); |
325 |
| - iframe.classList.remove('loaded'); |
326 |
| - parentNode?.removeChild(iframe); |
327 |
| - iframe.src = src; |
328 |
| - parentNode?.appendChild(iframe); |
329 |
| - } |
330 |
| -
|
331 | 314 | /** @param {string} path */
|
332 | 315 | function route_to(path) {
|
333 | 316 | if (adapter) {
|
334 | 317 | const url = new URL(path, adapter.base);
|
335 | 318 | path = url.pathname + url.search + url.hash;
|
336 |
| - set_iframe_src(adapter.base + path); |
| 319 | + iframe.src = adapter.base + path; |
337 | 320 | }
|
338 | 321 | }
|
339 | 322 |
|
|
468 | 451 | {loading}
|
469 | 452 | on:refresh={() => {
|
470 | 453 | if (adapter) {
|
471 |
| - set_iframe_src(adapter.base + path); |
| 454 | + iframe.src = adapter.base + path; |
472 | 455 | }
|
473 | 456 | }}
|
474 | 457 | on:change={(e) => nav_to(e.detail.value)}
|
|
556 | 539 | background: var(--sk-back-2);
|
557 | 540 | }
|
558 | 541 |
|
559 |
| - iframe:not(.loaded) { |
560 |
| - display: none; |
561 |
| - } |
562 |
| -
|
563 | 542 | .editor-container {
|
564 | 543 | position: relative;
|
565 | 544 | background-color: var(--sk-back-3);
|
|
0 commit comments