@@ -6,15 +6,15 @@ export interface DeckdeckgoSlide {
66
77export class DeckDeckGoSlideUtils {
88
9- static hideElements ( el : HTMLElement , revealShowFirst : boolean ) : Promise < void > {
9+ static hideRevealElements ( el : HTMLElement , revealShowFirst : boolean ) : Promise < void > {
1010 return new Promise < void > ( ( resolve ) => {
1111 // No keyboard on mobile device to reveal elements
1212 if ( this . isMobile ( ) ) {
1313 resolve ( ) ;
1414 return ;
1515 }
1616
17- const elements : NodeListOf < HTMLElement > = el . querySelectorAll ( revealShowFirst ? '[slot] > li:not(:first-child), [slot] > p:not(:first-child), [slot] > span:not(:first-child) [slot] > img:not(:first-child)' : '[slot] > li, [slot] > p, [slot] > span, [slot] > img' ) ;
17+ const elements : NodeListOf < HTMLElement > = el . querySelectorAll ( revealShowFirst ? '[slot] > li:not(:first-child), [slot] > p:not(:first-child), [slot] > span:not(:first-child), [slot] > img:not(:first-child)' : '[slot] > li, [slot] > p, [slot] > span, [slot] > img, img' ) ;
1818
1919 if ( ! elements ) {
2020 resolve ( ) ;
@@ -26,7 +26,7 @@ export class DeckDeckGoSlideUtils {
2626 } ) ;
2727 }
2828
29- private static showElement ( el : HTMLElement ) : Promise < boolean > {
29+ private static showRevealElement ( el : HTMLElement ) : Promise < boolean > {
3030 return new Promise < boolean > ( ( resolve ) => {
3131 const elements : NodeListOf < HTMLElement > = el . querySelectorAll ( '[slot] > li, [slot] > p, [slot] > span, [slot] > img' ) ;
3232
@@ -47,7 +47,7 @@ export class DeckDeckGoSlideUtils {
4747 } ) ;
4848 }
4949
50- private static hideElement ( el : HTMLElement ) : Promise < boolean > {
50+ private static hideRevealElement ( el : HTMLElement ) : Promise < boolean > {
5151 return new Promise < boolean > ( ( resolve ) => {
5252 const elements : NodeListOf < HTMLElement > = el . querySelectorAll ( '[slot] > li, [slot] > p, [slot] > span, [slot] > img' ) ;
5353
@@ -72,25 +72,42 @@ export class DeckDeckGoSlideUtils {
7272 static beforeSwipe ( el : HTMLElement , swipeLeft : boolean , reveal : boolean ) : Promise < boolean > {
7373 return new Promise < boolean > ( async ( resolve ) => {
7474 if ( reveal ) {
75- const couldSwipe : boolean = swipeLeft ? await this . showElement ( el ) : await this . hideElement ( el ) ;
75+ const couldSwipe : boolean = swipeLeft ? await this . showRevealElement ( el ) : await this . hideRevealElement ( el ) ;
7676 resolve ( couldSwipe ) ;
7777 } else {
7878 resolve ( true ) ;
7979 }
8080 } ) ;
8181 }
8282
83- static async lazyLoadImages ( el : HTMLElement ) : Promise < void > {
83+ static hideLazyLoadImages ( el : HTMLElement ) : Promise < void > {
8484 return new Promise < void > ( ( resolve ) => {
85- const allSlotedImages : NodeListOf < HTMLElement > = el . querySelectorAll ( '[slot] > img' ) ;
86- const allShadowImages : NodeListOf < HTMLElement > = el . shadowRoot . querySelectorAll ( 'img' ) ;
85+ let images : HTMLElement [ ] = this . getAllImages ( el ) ;
8786
88- const images : HTMLElement [ ] = Array . from ( allSlotedImages ) . concat ( Array . from ( allShadowImages ) ) ;
87+ if ( ! images ) {
88+ resolve ( ) ;
89+ } else {
90+ images = images . filter ( ( image : HTMLElement ) => image . getAttribute ( 'data-src' ) ) ;
91+
92+ images . forEach ( ( image : HTMLElement ) => {
93+ image . style . setProperty ( 'visibility' , 'hidden' ) ;
94+ } ) ;
95+
96+ resolve ( ) ;
97+ }
98+ } ) ;
99+ }
100+
101+ static async lazyLoadImages ( el : HTMLElement ) : Promise < void > {
102+ return new Promise < void > ( ( resolve ) => {
103+ const images : HTMLElement [ ] = this . getAllImages ( el ) ;
89104
90105 images . forEach ( ( image : HTMLElement ) => {
91106 if ( image . getAttribute ( 'data-src' ) ) {
92107 image . setAttribute ( 'src' , image . getAttribute ( 'data-src' ) ) ;
93108 image . removeAttribute ( 'data-src' ) ;
109+
110+ image . style . setProperty ( 'visibility' , 'initial' ) ;
94111 }
95112
96113 // Furthermore to lazy loading, we set pointer-events to none. Doing so we prevent images of being dragged.
@@ -101,6 +118,13 @@ export class DeckDeckGoSlideUtils {
101118 } ) ;
102119 } ;
103120
121+ static getAllImages ( el : HTMLElement ) : HTMLElement [ ] {
122+ const allSlotedImages : NodeListOf < HTMLElement > = el . querySelectorAll ( '[slot] > img' ) ;
123+ const allShadowImages : NodeListOf < HTMLElement > = el . shadowRoot . querySelectorAll ( 'img' ) ;
124+
125+ return Array . from ( allSlotedImages ) . concat ( Array . from ( allShadowImages ) ) ;
126+ }
127+
104128 // Source: http://detectmobilebrowsers.com
105129 static isMobile ( ) : boolean {
106130 if ( ! window ) {
0 commit comments