mirror of
https://github.com/a2nt/meta-lightbox.git
synced 2024-10-22 17:05:53 +02:00
FIX: iframe wasn't loaded at specific timming
This commit is contained in:
parent
e3ee9ec1ba
commit
d1d75947c5
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@a2nt/meta-lightbox",
|
"name": "@a2nt/meta-lightbox",
|
||||||
"version": "2.3.5",
|
"version": "2.3.6",
|
||||||
"description": "Universal Lightbox window",
|
"description": "Universal Lightbox window",
|
||||||
"main": "meta-lightbox.js",
|
"main": "meta-lightbox.js",
|
||||||
"author": "Tony Air <tony@twma.pro>",
|
"author": "Tony Air <tony@twma.pro>",
|
||||||
|
@ -505,12 +505,6 @@ const MetaLightboxUI = (($) => {
|
|||||||
static loadIframe(href, classTerm) {
|
static loadIframe(href, classTerm) {
|
||||||
const ui = this;
|
const ui = this;
|
||||||
|
|
||||||
// don't load on offline
|
|
||||||
if ($Body.hasClass('is-offline')) {
|
|
||||||
console.warn(`${NAME}: Unable to load iframe offline`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const $iframe = $('<iframe>', {
|
const $iframe = $('<iframe>', {
|
||||||
src: href,
|
src: href,
|
||||||
class: classTerm,
|
class: classTerm,
|
||||||
@ -524,29 +518,41 @@ const MetaLightboxUI = (($) => {
|
|||||||
console.log(`${NAME}: loading iframe`);
|
console.log(`${NAME}: loading iframe`);
|
||||||
|
|
||||||
$Body.append(
|
$Body.append(
|
||||||
'<div id="IFramePreload" class="hidden d-none iframe-preload" style="display:none"></div>',
|
'<div id="MetaIFramePreload" class="hidden d-none iframe-preload" style="display:none"></div>',
|
||||||
);
|
);
|
||||||
const $preload = $('#IFramePreload');
|
const $preload = $('#MetaIFramePreload');
|
||||||
$preload.html($iframe);
|
$preload.html($iframe);
|
||||||
|
|
||||||
$iframe.on('load', () => {
|
$iframe.on('load', () => {
|
||||||
console.log(`${NAME}: the iframe was loaded`);
|
// don't load on offline
|
||||||
$preload.html('');
|
if ($Body.hasClass('is-offline')) {
|
||||||
$preload.remove();
|
console.warn(`${NAME}: Unable to load iframe offline`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ui.$content.addClass('iframe-delay');
|
ui.finishIFrameLoading($preload, $iframe);
|
||||||
|
|
||||||
ui.$content.html($iframe);
|
|
||||||
ui.contentLoaded();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
ui.$content.removeClass('iframe-delay');
|
|
||||||
}, 1000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $iframe;
|
return $iframe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static finishIFrameLoading() {
|
||||||
|
const ui = this;
|
||||||
|
|
||||||
|
console.log(`${NAME}: the iframe was loaded`);
|
||||||
|
$preload.html('');
|
||||||
|
$preload.remove();
|
||||||
|
|
||||||
|
ui.$content.addClass('iframe-delay');
|
||||||
|
|
||||||
|
ui.$content.html($iframe);
|
||||||
|
ui.contentLoaded();
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
ui.$content.removeClass('iframe-delay');
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
static contentLoaded() {
|
static contentLoaded() {
|
||||||
const ui = this;
|
const ui = this;
|
||||||
|
|
||||||
@ -617,8 +623,17 @@ const MetaLightboxUI = (($) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$W.on(`${Events.BACKONLINE}`, () => {
|
$W.on(`${Events.BACKONLINE}`, () => {
|
||||||
const $iframe = $('.meta-lightbox-content iframe');
|
|
||||||
console.log(`${NAME}: reloading iframe`);
|
console.log(`${NAME}: reloading iframe`);
|
||||||
|
|
||||||
|
const $preload = $('#MetaIFramePreload');
|
||||||
|
if ($preload.length) {
|
||||||
|
const $iframe = $preload.find('iframe');
|
||||||
|
if ($iframe.length) {
|
||||||
|
ui.finishIFrameLoading($preload, $iframe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const $iframe = $('.meta-lightbox-content iframe');
|
||||||
$iframe.attr('src', $iframe.attr('src'));
|
$iframe.attr('src', $iframe.attr('src'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user