1(function ($) { 2 3 "use strict"; 4 5 $(document).ready(function() { 6 7 8 // Pure vanilla JS solution by fabulous Dmitry Semenov. 9 // http://photoswipe.com/documentation/getting-started.html 10 // Some options changed. numNodes counter altered. 11 12 13 var initPhotoSwipeFromDOM = function(gallerySelector) { 14 15 // parse slide data (url, title, size ...) from DOM elements 16 // (children of gallerySelector) 17 var parseThumbnailElements = function(el) { 18 var thumbElements = el.childNodes, 19 numNodes = thumbElements.length, 20 items = [], 21 figureEl, 22 linkEl, 23 size, 24 item; 25 26 for(var i = 0; i < numNodes; i++) { 27 28 figureEl = thumbElements[i]; // <figure> element 29 30 // include only element nodes 31 if(figureEl.nodeType !== 1) { 32 continue; 33 } 34 35 linkEl = figureEl.children[0]; // <a> element 36 37 size = linkEl.getAttribute('data-size').split('x'); 38 39 // create slide object 40 item = { 41 src: linkEl.getAttribute('href'), 42 w: parseInt(size[0], 10), 43 h: parseInt(size[1], 10) 44 }; 45 46 47 48 if(figureEl.children.length > 1) { 49 // <figcaption> content 50 item.title = figureEl.children[1].innerHTML; 51 } 52 53 if(linkEl.children.length > 0) { 54 // <img> thumbnail element, retrieving thumbnail url 55 // item.msrc = linkEl.children[0].getAttribute('src'); 56 } 57 58 item.el = figureEl; // save link to element for getThumbBoundsFn 59 items.push(item); 60 } 61 62 return items; 63 }; 64 65 // find nearest parent element 66 var closest = function closest(el, fn) { 67 return el && ( fn(el) ? el : closest(el.parentNode, fn) ); 68 }; 69 70 // triggers when user clicks on thumbnail 71 var onThumbnailsClick = function(e) { 72 e = e || window.event; 73 e.preventDefault ? e.preventDefault() : e.returnValue = false; 74 75 var eTarget = e.target || e.srcElement; 76 77 // find root element of slide 78 var clickedListItem = closest(eTarget, function(el) { 79 return (el.tagName && el.tagName.toUpperCase() === 'FIGURE'); 80 }); 81 82 if(!clickedListItem) { 83 return; 84 } 85 86 // find index of clicked item by looping through all child nodes 87 // alternatively, you may define index via data- attribute 88 var clickedGallery = clickedListItem.parentNode, 89 childNodes = clickedListItem.parentNode.childNodes, 90 numChildNodes = childNodes.length, 91 nodeIndex = 0, 92 index; 93 94 for (var i = 0; i < numChildNodes; i++) { 95 if(childNodes[i].nodeType !== 1) { 96 continue; 97 } 98 99 if(childNodes[i] === clickedListItem) { 100 index = nodeIndex; 101 break; 102 } 103 nodeIndex++; 104 } 105 106 107 108 if(index >= 0) { 109 // open PhotoSwipe if valid index found 110 openPhotoSwipe( index, clickedGallery ); 111 } 112 return false; 113 }; 114 115 // parse picture index and gallery index from URL (#&pid=1&gid=2) 116 var photoswipeParseHash = function() { 117 var hash = window.location.hash.substring(1), 118 params = {}; 119 120 if(hash.length < 5) { 121 return params; 122 } 123 124 var vars = hash.split('&'); 125 for (var i = 0; i < vars.length; i++) { 126 if(!vars[i]) { 127 continue; 128 } 129 var pair = vars[i].split('='); 130 if(pair.length < 2) { 131 continue; 132 } 133 params[pair[0]] = pair[1]; 134 } 135 136 if(params.gid) { 137 params.gid = parseInt(params.gid, 10); 138 } 139 140 return params; 141 }; 142 143 var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) { 144 var pswpElement = document.querySelectorAll('.pswp')[0], 145 gallery, 146 options, 147 items; 148 149 items = parseThumbnailElements(galleryElement); 150 151 // Should we show the share link? 152 if ($('body').hasClass('mauer-narrator-share-from-lightbox')) {var shareEl = true;} else {var shareEl = false;} 153 154 // define options (if needed) 155 options = { 156 // define gallery index (for URL) 157 galleryUID: galleryElement.getAttribute('data-pswp-uid'), 158 159 showHideOpacity: true, 160 getThumbBoundsFn: false, 161 hideAnimationDuration: 0, 162 showAnimationDuration: 0, 163 shareEl: shareEl, 164 preloaderEl: true, 165 closeOnScroll: false, 166 shareButtons: [ 167 {id: 'facebook', label: '<i class="fa fa-facebook-official" aria-hidden="true"></i>', url: 'https://www.facebook.com/sharer/sharer.php?u={{url}}'}, 168 {id: 'twitter', label: '<i class="fa fa-twitter" aria-hidden="true"></i>', url: 'https://twitter.com/intent/tweet?text={{text}}&url={{url}}'}, 169 {id: 'pinterest', label: '<i class="fa fa-pinterest" aria-hidden="true"></i>', url: 'http://www.pinterest.com/pin/create/button/?url={{url}}&media={{image_url}}&description={{text}}'} 170 ], 171 }; 172 173 // PhotoSwipe opened from URL 174 if(fromURL) { 175 if(options.galleryPIDs) { 176 // parse real index when custom PIDs are used 177 // http://photoswipe.com/documentation/faq.html#custom-pid-in-url 178 for(var j = 0; j < items.length; j++) { 179 if(items[j].pid == index) { 180 options.index = j; 181 break; 182 } 183 } 184 } else { 185 // in URL indexes start from 1 186 options.index = parseInt(index, 10) - 1; 187 } 188 } else { 189 options.index = parseInt(index, 10); 190 } 191 192 // exit if index not found 193 if( isNaN(options.index) ) { 194 return; 195 } 196 197 if(disableAnimation) { 198 options.showAnimationDuration = 0; 199 } 200 201 // Pass data to PhotoSwipe and initialize it 202 gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options); 203 gallery.init(); 204 }; 205 206 // loop through all gallery elements and bind events 207 var galleryElements = document.querySelectorAll( gallerySelector ); 208
209 for(var i = 0, l = galleryElements.length; i < l; i++) { 210 galleryElements[i].setAttribute('data-pswp-uid', i+1); 211 galleryElements[i].onclick = onThumbnailsClick; 212 } 213 214 // Parse URL and open gallery if it contains #&pid=3&gid=1 215 var hashData = photoswipeParseHash(); 216 if(hashData.pid && hashData.gid) { 217 openPhotoSwipe( hashData.pid , galleryElements[ hashData.gid - 1 ], true, true ); 218 } 219 }; 220 221 // execute above function 222 initPhotoSwipeFromDOM('.mauer-narrator-pswp-gallery'); 223 224 225 }); 226 227})(jQuery);
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.