1(function() { 2 3 window.initPhotoSwipeFromDOM = function(gallerySelector) { 4 5 var parseThumbnailElements = function(el) { 6 var thumbElements = el.querySelectorAll('.gallery-list'); 7 8 if(!thumbElements.length) 9 thumbElements = el.querySelectorAll('.fancybox'); 10 if(!thumbElements.length) 11 thumbElements = el.querySelectorAll('.fancybox_ext'); 12// console.log(thumbElements); 13 var numNodes = thumbElements.length, 14 items = [], 15 el, 16 childElements, 17 thumbnailEl, 18 size, 19 item; 20 21 for(var i = 0; i < numNodes; i++) { 22 el = thumbElements[i]; 23 24 // include only element nodes 25 if(el.nodeType !== 1) { 26 continue; 27 } 28 29 childElements = el.children; 30 31 size = el.getAttribute('data-size').split('x'); 32 33 // create slide object 34 item = { 35 src: el.getAttribute('data-href') ? el.getAttribute('data-href') : el.getAttribute('href'), 36 w: parseInt(size[0], 10), 37 h: parseInt(size[1], 10) 38 }; 39 40 41 item.el = el; // save link to element for getThumbBoundsFn 42 43 if(childElements.length > 0) { 44 item.msrc = childElements[0].getAttribute('src'); // thumbnail url 45 if(childElements.length > 1) { 46 item.title = childElements[1].innerHTML; // caption (contents of figure) 47 } 48 } 49 50 // original image 51 item.o = { 52 src: item.src, 53 w: item.w, 54 h: item.h 55 }; 56 57 items.push(item); 58 } 59 60 return items; 61 }; 62
63 // find nearest parent element 64 var closest = function closest(el, fn) { 65 return el && ( fn(el) ? el : closest(el.parentNode, fn) ); 66 }; 67 68 var onThumbnailsClick = function(e) { 69 e = e || window.event; 70 71 e.preventDefault ? e.preventDefault() : e.returnValue = false; 72 73 var eTarget = e.target || e.srcElement; 74 75 var clickedListItem = closest(eTarget, function(el) { 76 return el.tagName === 'A'; 77 }); 78 79 if(!clickedListItem) { 80 return; 81 } 82 // var clickedGallery = clickedListItem.parentNode; 83 var clickedGallery = clickedListItem.closest(gallerySelector); 84 // var childNodes = clickedListItem.parentNode.childNodes, 85 var childNodes = clickedGallery.querySelectorAll('.gallery-list'); 86 if(!childNodes.length) 87 childNodes = clickedGallery.querySelectorAll('.fancybox'); 88 if(!childNodes.length) 89 childNodes = clickedGallery.querySelectorAll('.fancybox_ext'); 90 // alert(childNodes.length); 91 var numChildNodes = childNodes.length, 92 nodeIndex = 0, 93 index; 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 if(index >= 0) { 108 openPhotoSwipe( index, clickedGallery ); 109 } 110 return false; 111 }; 112 113 var photoswipeParseHash = function() { 114 var hash = window.location.hash.substring(1), 115 params = {}; 116 117 if(hash.length < 5) { // pid=1 118 return params; 119 } 120 121 var vars = hash.split('&'); 122 123 for (var i = 0; i < vars.length; i++) { 124 if(!vars[i]) { 125 continue; 126 } 127 var pair = vars[i].split('='); 128 if(pair.length < 2) { 129 continue; 130 } 131 params[pair[0]] = pair[1]; 132 } 133 134 if(params.gid) { 135 params.gid = parseInt(params.gid, 10); 136 } 137 138 return params; 139 }; 140 141 var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) { 142 var pswpElement = document.querySelectorAll('.pswp')[0], 143 gallery, 144 options, 145 items; 146 items = parseThumbnailElements(galleryElement); 147 148 // define options (if needed) 149 options = { 150 bgOpacity: 0.5, 151 galleryUID: galleryElement.getAttribute('data-pswp-uid'), 152 shareEl: false, 153 getThumbBoundsFn: function(index) { 154 // See Options->getThumbBoundsFn section of docs for more info 155 var thumbnail = items[index].el.children[0] ? items[index].el.children[0] : items[index].el, 156 pageYScroll = window.pageYOffset || document.documentElement.scrollTop, 157 rect = thumbnail.getBoundingClientRect(); 158 159 return {x:rect.left, y:rect.top + pageYScroll, w:rect.width}; 160 } 161 }; 162 163 164 if(fromURL) { 165 if(options.galleryPIDs) { 166 // parse real index when custom PIDs are used 167 // http://photoswipe.com/documentation/faq.html#custom-pid-in-url 168 for(var j = 0; j < items.length; j++) { 169 if(items[j].pid == index) { 170 options.index = j; 171 break; 172 } 173 } 174 } else { 175 options.index = parseInt(index, 10) - 1; 176 } 177 } else { 178 options.index = parseInt(index, 10); 179 } 180 181 // exit if index not found 182 if( isNaN(options.index) ) { 183 return; 184 } 185 186 var radios = document.getElementsByName('gallery-style'); 187 for (var i = 0, length = radios.length; i < length; i++) { 188 if (radios[i].checked) { 189 if(radios[i].id == 'radio-all-controls') { 190 191 } else if(radios[i].id == 'radio-minimal-black') { 192 options.mainClass = 'pswp--minimal--dark'; 193 options.barsSize = {top:0,bottom:0}; 194 options.captionEl = false; 195 options.fullscreenEl = false; 196 options.shareEl = false; 197 options.bgOpacity = 0.85; 198 options.tapToClose = true; 199 options.tapToToggleControls = false; 200 } 201 break; 202 } 203 } 204 205 if(disableAnimation) { 206 options.showAnimationDuration = 0; 207 } 208 startPhotoSwipe( pswpElement, items, options); 209 // Pass data to PhotoSwipe and initialize it 210 // see: http://photoswipe.com/documentation/responsive-images.html 211 }; 212 var startPhotoSwipe = function( pswpElement, items, options) { 213 if(!!window.PhotoSwipe){ 214 var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options); 215 gallery.init(); 216 }else 217 setTimeout(function(){startPhotoSwipe( pswpElement, items, options)}, 300); 218 219 }; 220 221 // select all gallery elements 222 var galleryElements = document.querySelectorAll( gallerySelector ); 223 for(var i = 0, l = galleryElements.length; i < l; i++) { 224 galleryElements[i].setAttribute('data-pswp-uid', i+1); 225 console.log(galleryElements[i]); 226 galleryElements[i].onclick = onThumbnailsClick; 227 } 228 229 // Parse URL and open gallery if it contains #&pid=3&gid=1 230 var hashData = photoswipeParseHash() 231 232 if(hashData.pid && hashData.gid) { 233 openPhotoSwipe( hashData.pid, galleryElements[ hashData.gid - 1 ], true, true ); 234 } 235 }; 236})();
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.