/* Theme Name: Minel Description: Versatile Coming Soon Site Template Author: Erilisdesign Theme URI: http://erilisdesign.com/preview/themeforest/html/minel/ Author URI: http://themeforest.net/user/erilisdesign Version: 1.0 License: https://themeforest.net/licenses/standard */ (function($) { "use strict"; // Vars var body = $('body'); // Photoswipe function init_ED_PhotoSwipe() { var initPhotoSwipeFromDOM = function(gallerySelector) { var parseThumbnailElements = function(el) { var thumbElements = el.childNodes, numNodes = thumbElements.length, items = [], articleEl, childElements, linkEl, size, item; for(var i = 0; i < numNodes; i++) { articleEl = thumbElements[i]; // include only element nodes if(articleEl.nodeType !== 1) { continue; } linkEl = articleEl.children[0].children[0]; size = linkEl.getAttribute('data-size').split('x'); // create slide object item = { src: linkEl.getAttribute('href'), w: parseInt(size[0], 10), h: parseInt(size[1], 10) }; item.title = true; item.el = articleEl; // save link to element for getThumbBoundsFn if(articleEl.children[0].children.length > 1) { item.details = articleEl.children[0].children[1].outerHTML; // caption (contents of figure) } if(linkEl.children.length > 0) { item.msrc = linkEl.children[0].getAttribute('src'); // thumbnail url } // original image item.o = { src: item.src, w: item.w, h: item.h }; items.push(item); } return items; }; // find nearest parent element var closest = function closest(el, fn) { return el && ( fn(el) ? el : closest(el.parentNode, fn) ); }; var onThumbnailsClick = function(e) { e = e || window.event; e.preventDefault ? e.preventDefault() : e.returnValue = false; var eTarget = e.target || e.srcElement; var clickedListItem = closest(eTarget, function(el) { return el.tagName === 'ARTICLE'; }); if(!clickedListItem) { return; } var clickedGallery = clickedListItem.parentNode, childNodes = clickedListItem.parentNode.childNodes, numChildNodes = childNodes.length, nodeIndex = 0, index; for (var i = 0; i < numChildNodes; i++) { if(childNodes[i].nodeType !== 1) { continue; } if(childNodes[i] === clickedListItem) { index = nodeIndex; break; } nodeIndex++; } if(index >= 0) { openPhotoSwipe( index, clickedGallery ); } return false; }; var photoswipeParseHash = function() { var hash = window.location.hash.substring(1), params = {}; if(hash.length < 5) { // pid=1 return params; } var vars = hash.split('&'); for (var i = 0; i < vars.length; i++) { if(!vars[i]) { continue; } var pair = vars[i].split('='); if(pair.length < 2) { continue; } params[pair[0]] = pair[1]; } if(params.gid) { params.gid = parseInt(params.gid, 10); } return params; }; var openPhotoSwipe = function(index, galleryElement, disableAnimation) { var pswpElement = document.querySelectorAll('.pswp')[0], gallery, options, items; items = parseThumbnailElements(galleryElement); // Define options options = { // Core index: index, getThumbBoundsFn: function(index) { // See Options->getThumbBoundsFn section of docs for more info var thumbnail = items[index].el.children[0], pageYScroll = window.pageYOffset || document.documentElement.scrollTop, rect = thumbnail.getBoundingClientRect(); return {x:rect.left, y:rect.top + pageYScroll, w:rect.width}; }, bgOpacity: 0.97, loop: true, closeOnScroll: false, history: false, galleryUID: galleryElement.getAttribute('data-pswp-uid'), focus: false, modal: false, // UI addCaptionHTMLFn: function(item, captionEl, isFake) { if(!item.details) { captionEl.children[0].innerText = ''; return false; } captionEl.children[0].innerHTML = item.details; return true; }, // Buttons/elements closeEl: true, captionEl: true, fullscreenEl: true, zoomEl: true, shareEl: true, counterEl: true, arrowEl: true, preloaderEl: true }; // Exit if index not found if( isNaN(options.index) ) { return; } if(disableAnimation) { options.showAnimationDuration = 0; } // Pass data to PhotoSwipe and initialize it gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options); // see: http://photoswipe.com/documentation/responsive-images.html var realViewportWidth, useLargeImages = false, firstResize = true, imageSrcWillChange; gallery.listen('beforeResize', function() { var dpiRatio = window.devicePixelRatio ? window.devicePixelRatio : 1; dpiRatio = Math.min(dpiRatio, 2.5); realViewportWidth = gallery.viewportSize.x * dpiRatio; if(realViewportWidth >= 1200 || (!gallery.likelyTouchDevice && realViewportWidth > 800) || screen.width > 1200 ) { if(!useLargeImages) { useLargeImages = true; imageSrcWillChange = true; } } else { if(useLargeImages) { useLargeImages = false; imageSrcWillChange = true; } } if(imageSrcWillChange && !firstResize) { gallery.invalidateCurrItems(); } if(firstResize) { firstResize = false; } imageSrcWillChange = false; }); gallery.listen('gettingData', function(index, item) { if( useLargeImages ) { item.src = item.o.src; item.w = item.o.w; item.h = item.o.h; } else { item.src = item.o.src; item.w = item.o.w; item.h = item.o.h; } }); gallery.init(); }; // select all gallery elements var galleryElements = document.querySelectorAll( gallerySelector ); for(var i = 0, l = galleryElements.length; i < l; i++) { galleryElements[i].setAttribute('data-pswp-uid', i+1); galleryElements[i].onclick = onThumbnailsClick; } // Parse URL and open gallery if it contains #&pid=3&gid=1 var hashData = photoswipeParseHash(); if(hashData.pid && hashData.gid) { openPhotoSwipe( hashData.pid, galleryElements[ hashData.gid - 1 ], true, true ); } }; initPhotoSwipeFromDOM('.portfolio-gallery'); } // document.ready function jQuery(document).ready(function($) { init_ED_PhotoSwipe(); }); })(jQuery);