From 5f19bb8699eb4c7ae5872702ccebd10f951d4dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rene=20Hamp=C3=B6lz?= Date: Sat, 12 Nov 2022 16:15:21 +0000 Subject: [PATCH] fix: Passed stylesheets are 'unloaded' after some time --- .../nextcloud/snappymail/js/snappymail.js | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/integrations/nextcloud/snappymail/js/snappymail.js b/integrations/nextcloud/snappymail/js/snappymail.js index e35697e65..a00402713 100644 --- a/integrations/nextcloud/snappymail/js/snappymail.js +++ b/integrations/nextcloud/snappymail/js/snappymail.js @@ -16,14 +16,28 @@ document.onreadystatechange = () => { }; document.addEventListener('DOMContentLoaded', () => { - passThemes(); -}); - -// Pass nextcloud themes and theme attributes to SnappyMail. -function passThemes() { const iframe = document.getElementById('rliframe'); if (!iframe) return; + let firstLoad = true; + + iframe.addEventListener('load', event => { + // repass theme styles when iframe is reloaded + if (!firstLoad) { + passThemes(event.target); + } + firstLoad = false; + }); + + passThemes(iframe); + + // TODO: add initial stylesheets without primary colors to improve loading experience +}); + +// Pass nextcloud themes and theme attributes to SnappyMail. +function passThemes(iframe) { + if (!iframe) return; + const target = iframe.contentWindow.document; const ncStylesheets = [...document.querySelectorAll('link.theme')];