// // Docs: http://photoswipe.com/documentation/options.html // define(['photoswipe', 'photoswipe_ui'], function(PhotoSwipe, PhotoSwipeUI_Default){ // PhotoSwipe und PhotoSwipeUI_Default sind Dependencies // write markup if necessary if( !$(".pswp").length ) { pswp_create_markup(); } var pswp_items = []; // get every item for image gallery $(".lightbox").each(function(){ // prepare item details var item = { src: $(this).find("a").attr("href"), w: $(this).find('[itemprop="width"]').attr("content"), h: $(this).find('[itemprop="height"]').attr("content"), pid: $(this).find("a").attr("href").replace(/.*\/(.*)?$/i, "$1"), el: $(this) } // copyright (author) if( $(this).find(".copyright-info").length ) { item.title = $(this).find(".copyright-info").html(); } else { var author = $(this).find('[itemprop="copyrightHolder"]').attr("content"); if( author && author != '' ) { item.title = '© ' + author; } } // thumbnail as image placeholder // if( $(this).is(":visible") ) { item.msrc = $(this).find("img").attr("src"); } pswp_items.push( item ); // open lightbox $(this).click(function(e){ console.log($(this)); e.preventDefault(); var options = { index: $(this).index(".lightbox"), showHideOpacity: true, shareEl: false, indexIndicatorSep: ' von ', galleryUID: '', galleryPIDs: true, getThumbBoundsFn: function(i){ return { x: $(pswp_items[i].el).find("img").offset().left, y: $(pswp_items[i].el).find("img").offset().top, w: $(pswp_items[i].el).find("img").width() }; } } var pswp_lightbox = new PhotoSwipe( $(".pswp")[0], PhotoSwipeUI_Default, pswp_items, options ); pswp_lightbox.listen("afterChange",function(){ try { // track as analytics event ga('send', 'event', 'Lightbox', 'Bild Detailansicht', pswp_lightbox.currItem.src); } catch(err){} }); pswp_lightbox.init(); }); }); return false; }); // write necessary markup to dom function pswp_create_markup() { var s = '
' + "\n"; $("body").append( s ); }