Spaces:
Running
Running
Swap preview to viewer only on viewer-ready postMessage
Browse files
app.js
CHANGED
|
@@ -217,20 +217,9 @@
|
|
| 217 |
lazyMedia.src = lazyMedia.dataset.src;
|
| 218 |
lazyMedia.removeAttribute('data-src');
|
| 219 |
}
|
| 220 |
-
// Load iframe (
|
| 221 |
var iframe = card.querySelector('iframe.lazy-iframe');
|
| 222 |
if (iframe && iframe.dataset.src) {
|
| 223 |
-
if (iframe.classList.contains('card-viewer-hidden')) {
|
| 224 |
-
iframe.addEventListener('load', function onLoad() {
|
| 225 |
-
iframe.removeEventListener('load', onLoad);
|
| 226 |
-
setTimeout(function () {
|
| 227 |
-
iframe.classList.remove('card-viewer-hidden');
|
| 228 |
-
iframe.classList.add('card-viewer-ready');
|
| 229 |
-
var preview = iframe.parentNode.querySelector('.card-preview');
|
| 230 |
-
if (preview) preview.classList.add('card-preview-hidden');
|
| 231 |
-
}, 1500);
|
| 232 |
-
});
|
| 233 |
-
}
|
| 234 |
iframe.src = iframe.dataset.src;
|
| 235 |
}
|
| 236 |
}
|
|
@@ -352,6 +341,21 @@
|
|
| 352 |
// ------------------------------------
|
| 353 |
var lazyObserver = null;
|
| 354 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
function observeLazyImages() {
|
| 356 |
if (!lazyObserver) {
|
| 357 |
lazyObserver = new IntersectionObserver(function (entries) {
|
|
@@ -359,19 +363,6 @@
|
|
| 359 |
if (entry.isIntersecting) {
|
| 360 |
var el = entry.target;
|
| 361 |
if (el.dataset.src) {
|
| 362 |
-
// For hidden iframes behind previews, set up the swap
|
| 363 |
-
if (el.classList.contains('card-viewer-hidden')) {
|
| 364 |
-
el.addEventListener('load', function onLoad() {
|
| 365 |
-
el.removeEventListener('load', onLoad);
|
| 366 |
-
// Wait a moment for WASM to render first frame
|
| 367 |
-
setTimeout(function () {
|
| 368 |
-
el.classList.remove('card-viewer-hidden');
|
| 369 |
-
el.classList.add('card-viewer-ready');
|
| 370 |
-
var preview = el.parentNode.querySelector('.card-preview');
|
| 371 |
-
if (preview) preview.classList.add('card-preview-hidden');
|
| 372 |
-
}, 1500);
|
| 373 |
-
});
|
| 374 |
-
}
|
| 375 |
el.src = el.dataset.src;
|
| 376 |
}
|
| 377 |
lazyObserver.unobserve(el);
|
|
|
|
| 217 |
lazyMedia.src = lazyMedia.dataset.src;
|
| 218 |
lazyMedia.removeAttribute('data-src');
|
| 219 |
}
|
| 220 |
+
// Load iframe (viewer-ready postMessage will handle the swap)
|
| 221 |
var iframe = card.querySelector('iframe.lazy-iframe');
|
| 222 |
if (iframe && iframe.dataset.src) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
iframe.src = iframe.dataset.src;
|
| 224 |
}
|
| 225 |
}
|
|
|
|
| 341 |
// ------------------------------------
|
| 342 |
var lazyObserver = null;
|
| 343 |
|
| 344 |
+
// Listen for viewer-ready messages from WASM iframes
|
| 345 |
+
window.addEventListener('message', function (e) {
|
| 346 |
+
if (e.data && e.data.type === 'viewer-ready' && e.data.clipId) {
|
| 347 |
+
var card = grid.querySelector('.clip-card[data-clip-id="' + e.data.clipId + '"]');
|
| 348 |
+
if (!card) return;
|
| 349 |
+
var iframe = card.querySelector('iframe.card-viewer-hidden');
|
| 350 |
+
if (iframe) {
|
| 351 |
+
iframe.classList.remove('card-viewer-hidden');
|
| 352 |
+
iframe.classList.add('card-viewer-ready');
|
| 353 |
+
var preview = card.querySelector('.card-preview');
|
| 354 |
+
if (preview) preview.classList.add('card-preview-hidden');
|
| 355 |
+
}
|
| 356 |
+
}
|
| 357 |
+
});
|
| 358 |
+
|
| 359 |
function observeLazyImages() {
|
| 360 |
if (!lazyObserver) {
|
| 361 |
lazyObserver = new IntersectionObserver(function (entries) {
|
|
|
|
| 363 |
if (entry.isIntersecting) {
|
| 364 |
var el = entry.target;
|
| 365 |
if (el.dataset.src) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
el.src = el.dataset.src;
|
| 367 |
}
|
| 368 |
lazyObserver.unobserve(el);
|