From 1cbcc2174223b288a1fb2ee32fb8037c13408295 Mon Sep 17 00:00:00 2001 From: Pablo Zmdl Date: Fri, 21 Feb 2025 11:16:51 +0100 Subject: [PATCH] Hide loading message in case of fast iframe loading Previously, in case the iframe was already fully loaded, the callbacks were not called, and thus the loading message didn't disappear. --- program/js/app.js | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/program/js/app.js b/program/js/app.js index 587293f3dc..f615fabb72 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -250,22 +250,17 @@ function rcube_webmail() { if (this.task === 'mail' && (this.env.action === 'preview' || this.env.action === 'show')) { document.querySelectorAll('iframe.framed-message-part').forEach((iframe) => { - // Resize twice initially: first time when the iframe's - // document was parsed, to already provide roughly the - // correct height; second time when all resources have been - // loaded, to finally ensure the correct height with all - // images etc. - iframe.addEventListener('DOMContentLoaded', () => this.resize_preview_iframe(iframe)); - iframe.addEventListener('load', () => { - this.resize_preview_iframe(iframe); - // Hide "Loading data" message. - $(iframe).siblings('.loading').hide(); - // Show notice - if (iframe.contentDocument.body.dataset.extlinks === 'true') { - $(this.gui_objects.remoteobjectsmsg).show(); - this.enable_command('load-remote', true); - } - }); + if (iframe.contentDocument.readyState === 'complete') { + this.iframe_actions_after_load(iframe); + } else { + // Resize twice initially: first time when the iframe's + // document was parsed, to already provide roughly the + // correct height; second time when all resources have been + // loaded, to finally ensure the correct height with all + // images etc. + iframe.addEventListener('DOMContentLoaded', () => this.resize_preview_iframe(iframe)); + iframe.addEventListener('load', () => this.iframe_actions_after_load(iframe)); + } // Also run on window resizes, because the changed text flow could need more space. window.addEventListener('resize', () => this.resize_preview_iframe(iframe)); }); @@ -10683,6 +10678,17 @@ function rcube_webmail() { setTimeout('window.print()', 10); }; + this.iframe_actions_after_load = function (iframe) { + this.resize_preview_iframe(iframe); + // Hide "Loading data" message. + $(iframe).siblings('.loading').hide(); + // Show notice + if (iframe.contentDocument.body.dataset.extlinks === 'true') { + $(this.gui_objects.remoteobjectsmsg).show(); + this.enable_command('load-remote', true); + } + }; + this.resize_preview_iframe = function (iframe) { // Cancel runs that we're scheduled ealier but didn't run yet. if (iframe.resizePreviewIframeTimer) {