@@ -3,8 +3,11 @@ import "regenerator-runtime/runtime"; // needed for ``await`` support
33import  Base  from  "../../core/base" ; 
44import  Parser  from  "../../core/parser" ; 
55import  dom  from  "../../core/dom" ; 
6+ import  logging  from  "../../core/logging" ; 
67import  utils  from  "../../core/utils" ; 
78
9+ const  log  =  logging . getLogger ( "pat.gallery" ) ; 
10+ 
811export  const  parser  =  new  Parser ( "gallery" ) ; 
912parser . addArgument ( "item-selector" ,  "a" ) ;  // selector for anchor element, which is added to the gallery. 
1013parser . addArgument ( "loop" ,  true ) ; 
@@ -80,7 +83,14 @@ export default Base.extend({
8083        e . preventDefault ( ) ; 
8184
8285        this . template . removeAttribute ( "hidden" ) ; 
83-         const  pswpElement  =  document . querySelector ( ".pswp" ) ; 
86+ 
87+         const  pswp_el  =  dom . querySelectorAllAndMe ( this . template ,  ".pswp" ) ?. [ 0 ] ; 
88+         if  ( ! pswp_el )  { 
89+             log . warn ( "No photoswipe template found." ) ; 
90+         } 
91+ 
92+         // Now - when all is set - prevent default action. 
93+         e . preventDefault ( ) ; 
8494
8595        const  index  = 
8696            this . images 
@@ -103,7 +113,7 @@ export default Base.extend({
103113            history : false , 
104114        } ; 
105115
106-         const  gallery  =  new  PhotoSwipe ( pswpElement ,  PhotoSwipeUI ,  this . images ,  options ) ; 
116+         const  gallery  =  new  PhotoSwipe ( pswp_el ,  PhotoSwipeUI ,  this . images ,  options ) ; 
107117        gallery . listen ( "gettingData" ,  function  ( index ,  item )  { 
108118            // Workaround for the fact that we don't know the image sizes. 
109119            // https://github.com/dimsemenov/PhotoSwipe/issues/796 
0 commit comments