@@ -248,29 +248,8 @@ function rcube_webmail() {
248248 parent . rcmail . unlock_frame ( ) ;
249249 }
250250
251- if ( this . task === 'mail' && ( this . env . action === 'preview' || this . env . action === 'show' ) ) {
252- document . querySelectorAll ( 'iframe.framed-message-part' ) . forEach ( ( iframe ) => {
253- // Resize twice initially: first time when the iframe's
254- // document was parsed, to already provide roughly the
255- // correct height; second time when all resources have been
256- // loaded, to finally ensure the correct height with all
257- // images etc.
258- iframe . addEventListener ( 'DOMContentLoaded' , ( ) => this . resize_preview_iframe ( iframe ) ) ;
259- iframe . addEventListener ( 'load' , ( ) => {
260- // Hide "Loading data" message.
261- $ ( iframe ) . siblings ( '.loading' ) . hide ( ) ;
262- // Show remote objects notice
263- if ( iframe . contentDocument . body . dataset . extlinks === 'true' ) {
264- $ ( this . gui_objects . remoteobjectsmsg ) . show ( ) ;
265- this . enable_command ( 'load-remote' , true ) ;
266- }
267- this . resize_preview_iframe ( iframe ) ;
268- } ) ;
269- // Only now set the 'src' attribute, after the event handlers, else they don't work reliably!
270- iframe . setAttribute ( 'src' , iframe . dataset . src ) ;
271- // Also run on window resizes, because the changed text flow could need more space.
272- window . addEventListener ( 'resize' , ( ) => this . resize_preview_iframe ( iframe ) ) ;
273- } ) ;
251+ if ( this . task === 'mail' && ( this . env . action === 'preview' || this . env . action === 'show' || this . env . action === 'print' ) ) {
252+ this . handleContentIframes ( ) ;
274253 }
275254
276255 // enable general commands
@@ -492,7 +471,7 @@ function rcube_webmail() {
492471 // show printing dialog unless decryption must be done first
493472 else if ( this . env . action == 'print' && this . env . uid ) {
494473 if ( ! this . env . is_pgp_content && ! this . env . pgp_mime_part ) {
495- this . print_dialog ( ) ;
474+ this . afterAllContentIframesLoaded ( ( ) => this . print_dialog ( ) ) ;
496475 }
497476 }
498477
@@ -4025,8 +4004,10 @@ function rcube_webmail() {
40254004 this . env . browser_capabilities . pgpmime = 1 ;
40264005 var keyring = this . env . mailvelope_main_keyring ? undefined : this . env . user_id ,
40274006 fn = function ( kr ) {
4028- ref . mailvelope_keyring = kr ;
4029- ref . mailvelope_init ( action , kr ) ;
4007+ this . afterAllContentIframesLoaded ( ( ) => {
4008+ ref . mailvelope_keyring = kr ;
4009+ ref . mailvelope_init ( action , kr ) ;
4010+ } ) ;
40304011 } ;
40314012
40324013 mailvelope . getVersion ( ) . then ( function ( v ) {
@@ -10696,6 +10677,54 @@ function rcube_webmail() {
1069610677 iframe . style . height = wantedHeight + 20 + 'px' ;
1069710678 iframe . resizePreviewIframeTimer = null ;
1069810679 } ;
10680+
10681+ this . handleContentIframes = function ( ) {
10682+ iframe_loaded_promises = [ ] ;
10683+ window . allContentIframesLoaded = false ;
10684+ document . querySelectorAll ( 'iframe.framed-message-part' ) . forEach ( ( iframe ) => {
10685+ promise = new Promise ( ( resolve , reject ) => {
10686+ // Resize twice initially: first time when the iframe's
10687+ // document was parsed, to already provide roughly the
10688+ // correct height; second time when all resources have been
10689+ // loaded, to finally ensure the correct height with all
10690+ // images etc.
10691+ iframe . addEventListener ( 'DOMContentLoaded' , ( ) => this . resize_preview_iframe ( iframe ) ) ;
10692+ iframe . addEventListener ( 'load' , ( ) => {
10693+ // Hide "Loading data" message.
10694+ $ ( iframe ) . siblings ( '.loading' ) . hide ( ) ;
10695+ // Show remote objects notice
10696+ if ( iframe . contentDocument . body . dataset . extlinks === 'true' ) {
10697+ $ ( this . gui_objects . remoteobjectsmsg ) . show ( ) ;
10698+ this . enable_command ( 'load-remote' , true ) ;
10699+ }
10700+ this . resize_preview_iframe ( iframe ) ;
10701+ resolve ( ) ;
10702+ } ) ;
10703+ // Only now set the 'src' attribute, after the event handlers, else they don't work reliably!
10704+ iframe . setAttribute ( 'src' , iframe . dataset . src ) ;
10705+ // Also run on window resizes, because the changed text flow could need more space.
10706+ window . addEventListener ( 'resize' , ( ) => this . resize_preview_iframe ( iframe ) ) ;
10707+ } ) ;
10708+ iframe_loaded_promises . push ( promise ) ;
10709+ } ) ;
10710+
10711+ Promise . all ( iframe_loaded_promises )
10712+ . then ( ( ) => {
10713+ window . allContentIframesLoaded = true ;
10714+ // Add a short timeout to allow the iframes to finish rendering.
10715+ setTimeout ( ( ) => window . dispatchEvent ( new Event ( 'allContentIframesLoaded' ) ) , 50 ) ;
10716+ } ) ;
10717+ } ;
10718+
10719+ this . afterAllContentIframesLoaded = function ( callback ) {
10720+ if ( window . allContentIframesLoaded === true ) {
10721+ callback ( ) ;
10722+ } else {
10723+ window . addEventListener ( 'allContentIframesLoaded' , ( ) => {
10724+ callback ( ) ;
10725+ } ) ;
10726+ }
10727+ } ;
1069910728} // end object rcube_webmail
1070010729
1070110730
0 commit comments