@@ -16,6 +16,7 @@ export default class SlideContent {
1616 this . Reveal = Reveal ;
1717
1818 this . startEmbeddedIframe = this . startEmbeddedIframe . bind ( this ) ;
19+ this . preventIframeAutoFocus = this . preventIframeAutoFocus . bind ( this ) ;
1920 this . ensureMobileMediaPlaying = this . ensureMobileMediaPlaying . bind ( this ) ;
2021
2122 }
@@ -62,12 +63,17 @@ export default class SlideContent {
6263 slide . style . display = displayValue ;
6364 }
6465
65- // Media elements with data-src attributes
66+ // Media and iframe elements with data-src attributes
6667 queryAll ( slide , 'img[data-src], video[data-src], audio[data-src], iframe[data-src]' ) . forEach ( element => {
67- if ( element . tagName !== 'IFRAME' || this . shouldPreload ( element ) ) {
68+ const isIframe = element . tagName === 'IFRAME' ;
69+ if ( ! isIframe || this . shouldPreload ( element ) ) {
6870 element . setAttribute ( 'src' , element . getAttribute ( 'data-src' ) ) ;
6971 element . setAttribute ( 'data-lazy-loaded' , '' ) ;
7072 element . removeAttribute ( 'data-src' ) ;
73+
74+ if ( isIframe ) {
75+ element . addEventListener ( 'load' , this . preventIframeAutoFocus ) ;
76+ }
7177 }
7278 } ) ;
7379
@@ -468,23 +474,7 @@ export default class SlideContent {
468474
469475 let iframe = event . target ;
470476
471- if ( this . Reveal . getConfig ( ) . preventIframeAutoFocus ) {
472-
473- let elapsed = 0 ;
474- const interval = 100 ;
475- const maxTime = 1000 ;
476- const checkFocus = ( ) => {
477- if ( document . activeElement === iframe ) {
478- document . activeElement . blur ( ) ;
479- } else if ( elapsed < maxTime ) {
480- elapsed += interval ;
481- setTimeout ( checkFocus , interval ) ;
482- }
483- } ;
484-
485- setTimeout ( checkFocus , interval ) ;
486-
487- }
477+ this . preventIframeAutoFocus ( event ) ;
488478
489479 if ( iframe && iframe . contentWindow ) {
490480
@@ -550,6 +540,7 @@ export default class SlideContent {
550540 // Generic postMessage API for non-lazy loaded iframes
551541 queryAll ( element , 'iframe' ) . forEach ( el => {
552542 if ( el . contentWindow ) el . contentWindow . postMessage ( 'slide:stop' , '*' ) ;
543+ el . removeEventListener ( 'load' , this . preventIframeAutoFocus ) ;
553544 el . removeEventListener ( 'load' , this . startEmbeddedIframe ) ;
554545 } ) ;
555546
@@ -591,4 +582,35 @@ export default class SlideContent {
591582
592583 }
593584
585+ /**
586+ * Prevents iframes from automatically focusing themselves.
587+ *
588+ * @param {Event } event
589+ */
590+ preventIframeAutoFocus ( event ) {
591+
592+ const iframe = event . target ;
593+
594+ console . log ( 111 )
595+
596+ if ( iframe && this . Reveal . getConfig ( ) . preventIframeAutoFocus ) {
597+
598+ let elapsed = 0 ;
599+ const interval = 100 ;
600+ const maxTime = 1000 ;
601+ const checkFocus = ( ) => {
602+ if ( document . activeElement === iframe ) {
603+ document . activeElement . blur ( ) ;
604+ } else if ( elapsed < maxTime ) {
605+ elapsed += interval ;
606+ setTimeout ( checkFocus , interval ) ;
607+ }
608+ } ;
609+
610+ setTimeout ( checkFocus , interval ) ;
611+
612+ }
613+
614+ }
615+
594616}
0 commit comments