1jQuery(function($) { 2 var PhotoSwipe = window.PhotoSwipe, 3 PhotoSwipeUI_Default = window.PhotoSwipeUI_Default; 4 5 $('body').on('click', 'a[data-size]', function(e) { 6 if( !PhotoSwipe || !PhotoSwipeUI_Default ) { 7 return; 8 } 9 10 e.preventDefault(); 11 openPhotoSwipe( this ); 12 }); 13 14 var parseThumbnailElements = function(gallery, el) { 15 var elements = $(gallery).find('a[data-size]').has('img'), 16 galleryItems = [], 17 index; 18 19 elements.each(function(i) { 20 var $el = $(this), 21 size = $el.data('size').split('x'), 22 caption; 23 24 if( $el.next().is('.wp-caption-text') ) { 25 // image with caption 26 caption = $el.next().text(); 27 } else if( $el.parent().next().is('.wp-caption-text') ) { 28 // gallery icon with caption 29 caption = $el.parent().next().text(); 30 } else { 31 caption = $el.attr('title'); 32 } 33 34 galleryItems.push({ 35 src: $el.attr('href'), 36 w: parseInt(size[0], 10), 37 h: parseInt(size[1], 10), 38 title: caption, 39 msrc: $el.find('img').attr('src'), 40 el: $el 41 }); 42 if( el === $el.get(0) ) { 43 index = i; 44 } 45 }); 46 47 return [galleryItems, parseInt(index, 10)]; 48 }; 49 50 var openPhotoSwipe = function( element, disableAnimation ) { 51 var pswpElement = $('.pswp').get(0), 52 galleryElement = $(element).parents('.gallery, .hentry, .main, body').first(), 53 gallery, 54 options, 55 items, index; 56 57 items = parseThumbnailElements(galleryElement, element); 58 index = items[1]; 59 items = items[0]; 60 61 options = { 62 index: index, 63 getThumbBoundsFn: function(index) { 64 var image = items[index].el.find('img'), 65 offset = image.offset(); 66 67 return {x:offset.left, y:offset.top, w:image.width()}; 68 }, 69 showHideOpacity: true, 70 history: false 71 }; 72 73 if(disableAnimation) { 74 options.showAnimationDuration = 0; 75 } 76 77 // Pass data to PhotoSwipe and initialize it 78 gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options); 79 gallery.init(); 80 }; 81 82});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.