@@ -3,8 +3,11 @@ import "regenerator-runtime/runtime"; // needed for ``await`` support
3
3
import Base from "../../core/base" ;
4
4
import Parser from "../../core/parser" ;
5
5
import dom from "../../core/dom" ;
6
+ import logging from "../../core/logging" ;
6
7
import utils from "../../core/utils" ;
7
8
9
+ const log = logging . getLogger ( "pat.gallery" ) ;
10
+
8
11
export const parser = new Parser ( "gallery" ) ;
9
12
parser . addArgument ( "item-selector" , "a" ) ; // selector for anchor element, which is added to the gallery.
10
13
parser . addArgument ( "loop" , true ) ;
@@ -80,7 +83,14 @@ export default Base.extend({
80
83
e . preventDefault ( ) ;
81
84
82
85
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 ( ) ;
84
94
85
95
const index =
86
96
this . images
@@ -103,7 +113,7 @@ export default Base.extend({
103
113
history : false ,
104
114
} ;
105
115
106
- const gallery = new PhotoSwipe ( pswpElement , PhotoSwipeUI , this . images , options ) ;
116
+ const gallery = new PhotoSwipe ( pswp_el , PhotoSwipeUI , this . images , options ) ;
107
117
gallery . listen ( "gettingData" , function ( index , item ) {
108
118
// Workaround for the fact that we don't know the image sizes.
109
119
// https://github.com/dimsemenov/PhotoSwipe/issues/796
0 commit comments