$( document ).on( "ready", function() { var options = { index: 0 }; var gallery = null; var pswpElements = $( ".pswp" ); if ( pswpElements.length ) { var nodes = $( ".silk-object.photoswipe img" ); var getPhotoSwipeImages = function() { var result = []; for ( var i = 0, il = nodes.length; i < il; i++ ) { // omdat de img een kans heeft niet meer te zijn wat het was ( door bv ObjectFitImages() ), // maken we tijdelijk een nieuw element om de naturalWidth en -Height uit te lezen var img = document.createElement( "img" ); img.setAttribute( "src", nodes[ i ].src ); var o = { w: img.naturalWidth, h: img.naturalHeight, src: nodes[ i ].src }; result.push( o ); } return result; }; for ( var i = 0, il = nodes.length; i < il; i++ ) { //var a = $( nodes[ i ].parentNode.parentNode.parentNode ).find( "a" ); //if ( a.length < 1 ) { var a = $( nodes[ i ] ).parents( ".silk-object.photoswipe" ); //} if ( a.length ) { ( function( i ) { $( a[ 0 ] ).on( "click", function( evt ) { if ( document.body.getAttribute( "data-simply-edit" ) !== null ) { return false; } var images = getPhotoSwipeImages(); options.index = i; gallery = new PhotoSwipe( pswpElements[ 0 ], PhotoSwipeUI_Default, images, options ) gallery.init(); evt.preventDefault(); evt.stopPropagation(); return false; } ); } )( i ); } } } } );