1var initPhotoSwipeFromDOM = function(gallerySelector) { 2 3 // parse slide data (url, title, size ...) from DOM elements 4 // (children of gallerySelector) 5 var parseThumbnailElements = function(el) { 6 /* NOT DIRECT PARENT var thumbElements = el.childNodes,*/ 7 var thumbElements = jQuery(el).find('figure'), 8 numNodes = thumbElements.length, 9 items = [], 10 figureEl, 11 linkEl, 12 size, 13 item; 14 15 for(var i = 0; i < numNodes; i++) { 16 17 figureEl = thumbElements[i]; // <figure> element 18 19 // include only element nodes 20 if(figureEl.nodeType !== 1) { 21 continue; 22 } 23 24 linkEl = figureEl.children[0]; // <a> element 25 26 27 size = linkEl.getAttribute('data-size').split('x'); 28 29 // create slide object 30 /* item = { 31 src: linkEl.getAttribute('href'), 32 w: parseInt(size[0], 10), 33 h: parseInt(size[1], 10) 34 };*/ 35 36 // create slide object 37 if (jQuery(linkEl).data('type') == 'video') { 38 item = { 39 html: jQuery(linkEl).data('video') 40 }; 41 } else { 42 item = { 43 src: linkEl.getAttribute('href'), 44 w: parseInt(size[0], 10), 45 h: parseInt(size[1], 10) 46 }; 47 } 48 49 50 51 if(figureEl.children.length > 1) { 52 // <figcaption> content 53 item.title = figureEl.children[1].innerHTML; 54 } 55 56 if(linkEl.children.length > 0) { 57 // <img> thumbnail element, retrieving thumbnail url 58 // item.msrc = linkEl.children[0].getAttribute('src'); 59 } 60 61 item.el = figureEl; // save link to element for getThumbBoundsFn 62 items.push(item); 63 } 64 65 return items; 66 }; 67 68 // find nearest parent element 69 var closest = function closest(el, fn) { 70 return el && ( fn(el) ? el : closest(el.parentNode, fn) ); 71 }; 72 73 // triggers when user clicks on thumbnail 74 //var onThumbnailsClick = function(e) { 75 var onThumbnailsClick = jQuery('.pg-photoswipe-button').on('click', function(e) { 76 e = e || window.event; 77 e.preventDefault ? e.preventDefault() : e.returnValue = false; 78 79 var eTarget = e.target || e.srcElement; 80 81 // find root element of slide 82 var clickedListItem = closest(eTarget, function(el) { 83 return (el.tagName && el.tagName.toUpperCase() === 'FIGURE'); 84 }); 85 86 if(!clickedListItem) { 87 return; 88 } 89 90 // find index of clicked item by looping through all child nodes 91 // alternatively, you may define index via data- attribute 92 /* NOT DIRECT PARENT var clickedGallery = clickedListItem.parentNode,*/ 93 //var clickedGallery = clickedListItem.parentNode.parentNode.parentNode.parentNode.parentNode, 94 var clickedGalleryObject = jQuery(clickedListItem).closest('div.pg-photoswipe'), 95 clickedGallery = clickedGalleryObject[0], 96 /* NOT DIRECT PARENT childNodes = clickedListItem.parentNode.childNodes,*/ 97 childNodes = jQuery(clickedGallery).find('figure'), 98 numChildNodes = childNodes.length, 99 nodeIndex = 0, 100 index; 101 102 103 for (var i = 0; i < numChildNodes; i++) { 104 105 if(childNodes[i].nodeType !== 1) { 106 continue; 107 } 108 109 if(childNodes[i] === clickedListItem) { 110 index = nodeIndex; 111 break; 112 } 113 nodeIndex++; 114 } 115 116 117 118 if(index >= 0) { 119 120 // open PhotoSwipe if valid index found 121 openPhotoSwipe( index, clickedGallery ); 122 } 123 return false; 124 }); 125 126 // parse picture index and gallery index from URL (#&pid=1&gid=2) 127 var photoswipeParseHash = function() { 128 var hash = window.location.hash.substring(1), 129 params = {}; 130 131 if(hash.length < 5) { 132 return params; 133 } 134 135 var vars = hash.split('&'); 136 for (var i = 0; i < vars.length; i++) { 137 if(!vars[i]) { 138 continue; 139 } 140 var pair = vars[i].split('='); 141 if(pair.length < 2) { 142 continue; 143 } 144 params[pair[0]] = pair[1]; 145 } 146 147 if(params.gid) { 148 params.gid = parseInt(params.gid, 10); 149 } 150 151 return params; 152 }; 153 154 var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) { 155 var pswpElement = document.querySelectorAll('.pswp')[0], 156 gallery, 157 options, 158 items; 159 160 items = parseThumbnailElements(galleryElement); 161 162 // define options (if needed) 163 /* options = { 164 165 // define gallery index (for URL) 166 galleryUID: galleryElement.getAttribute('data-pswp-uid'), 167 168 getThumbBoundsFn: function(index) { 169 // See Options -> getThumbBoundsFn section of documentation for more info 170 var thumbnail = items[index].el.getElementsByTagName('img')[0], // find thumbnail 171 pageYScroll = window.pageYOffset || document.documentElement.scrollTop, 172 rect = thumbnail.getBoundingClientRect(); 173 174 return {x:rect.left, y:rect.top + pageYScroll, w:rect.width}; 175 } 176 177 };*/ 178 179 options = { 180 181 // define gallery index (for URL) 182 galleryUID: galleryElement.getAttribute('data-pswp-uid'), 183 184 getThumbBoundsFn: function(index) { 185 // See Options -> getThumbBoundsFn section of documentation for more info 186 var thumbnail = items[index].el.getElementsByTagName('img')[0], // find thumbnail 187 pageYScroll = window.pageYOffset || document.documentElement.scrollTop, 188 rect = thumbnail.getBoundingClientRect(); 189 190 return {x:rect.left, y:rect.top + pageYScroll, w:rect.width}; 191 }, 192 showHideOpacity: true, 193 getThumbBoundsFn: false 194 195 }; 196 197 // PhotoSwipe opened from URL 198 if(fromURL) { 199 if(options.galleryPIDs) { 200 // parse real index when custom PIDs are used 201 // http://photoswipe.com/documentation/faq.html#custom-pid-in-url 202 for(var j = 0; j < items.length; j++) { 203 if(items[j].pid == index) { 204 options.index = j; 205 break; 206 } 207 } 208 } else { 209 // in URL indexes start from 1 210 options.index = parseInt(index, 10) - 1; 211 } 212 } else { 213 options.index = parseInt(index, 10); 214 } 215 216 // exit if index not found 217 if( isNaN(options.index) ) { 218 return; 219 } 220 221 if(disableAnimation) { 222 options.showAnimationDuration = 0; 223 } 224 225 // Pass data to PhotoSwipe and initialize it 226 gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options); 227 228 229 /* SLIDESHOW */ 230 setSlideshowState(ssButtonClass, true /* not running from the start */); 231 232 // start timer for the next slide in slideshow after prior image has loaded 233 gallery.listen('afterChange', function() { 234 if (ssRunning && ssOnce) { 235 ssOnce = false;
236 setTimeout(gotoNextSlide, ssDelay); 237 } 238 }); 239 gallery.listen('destroy', function() { gallery = null; }); 240 /* END SLIDESHOW */ 241 242 gallery.init(); 243 244 /* YouTube */ 245 gallery.listen('beforeChange', function() { 246 var currItem = jQuery(gallery.currItem.container); 247 jQuery('.ph-pswp-video-wrapper iframe').removeClass('active'); 248 var currItemIframe = currItem.find('.ph-pswp-video-wrapper iframe').addClass('active'); 249 jQuery('.ph-pswp-video-wrapper iframe').each(function() { 250 if (!jQuery(this).hasClass('active')) { 251 jQuery(this).attr('src', jQuery(this).attr('src')); 252 } 253 }); 254 }); 255 256 257 258 gallery.listen('close', function() { 259 gallery.close(); 260 history.pushState("", document.title, window.location.pathname); 261 jQuery('.ph-pswp-video-wrapper iframe').each(function() { 262 jQuery(this).attr('src', jQuery(this).attr('src')); 263 }); 264 }); 265 266 267 /* SLIDESHOW FUNCTIONS */ 268 269 // slideshow vars: 270 var ssRunning = false, 271 ssOnce = false, 272 ssDelay = 2500 /*ms*/, 273 ssButtonClass = '.pswp__button--playpause'; 274 275 /* slideshow management */ 276 jQuery(ssButtonClass).on('click touchstart', function(e) { 277 // toggle slideshow on/off 278 setSlideshowState(this, !ssRunning); 279 //gallery.next(); 280 }); 281 282 283 284 function setSlideshowState(el, running) { 285 286 if (running) { 287 setTimeout(gotoNextSlide, ssDelay / 2.0 /* first time wait less */); 288 } 289 var title = running ? jQuery('#phTxtPauseSlideshow').text() : jQuery('#phTxtPlaySlideshow').text(); 290 jQuery(el).removeClass(running ? "play" : "pause") // change icons defined in css 291 .addClass(running ? "pause" : "play") 292 .prop('title', title); 293 ssRunning = running; 294 } 295 296 function gotoNextSlide() { 297 if (ssRunning && !!gallery) { 298 ssOnce = true; 299 gallery.next(); 300 // start counter for next slide in 'afterChange' listener 301 } 302 } 303 304 /* override handling of Esc key to stop slideshow on first esc (note Esc to leave fullscreen never gets here) */ 305 jQuery(document).keydown(function(e) { 306 if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) return; 307 if ((e.key === "Escape" || e.which == 27 /*esc*/) && !!gallery) { 308 if (e.preventDefault) e.preventDefault(); 309 else e.returnValue = false; 310 if (ssRunning) { 311 setSlideshowState(ssButtonClass, false); 312 } else { 313 gallery.close(); 314 } 315 } 316 }); 317 318 319 /* END SLIDESHOW FUNCTIONS */ 320 321 /* END SLIDESHOW FUNCTIONS */ 322 gallery.listen('close', function() { 323 // Second attempt to close gallery 324 gallery.close(); 325 // Remove history in case it will be not removed by close 326 history.pushState("", document.title, window.location.pathname); 327 // Forse stopping of slideshow 328 setSlideshowState(ssButtonClass, false); 329 }); 330 331 }; 332 333 // loop through all gallery elements and bind events 334 var galleryElements = document.querySelectorAll( gallerySelector ); 335 336 for(var i = 0, l = galleryElements.length; i < l; i++) { 337 galleryElements[i].setAttribute('data-pswp-uid', i+1); 338 galleryElements[i].onclick = onThumbnailsClick; 339 } 340 341 // Parse URL and open gallery if it contains #&pid=3&gid=1 342 var hashData = photoswipeParseHash(); 343 if(hashData.pid && hashData.gid) { 344 openPhotoSwipe( hashData.pid , galleryElements[ hashData.gid - 1 ], true, true ); 345 } 346}; 347 348// execute above function 349initPhotoSwipeFromDOM('.pg-photoswipe');
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.