Created
April 13, 2016 16:34
-
-
Save masterkitano/1abc4c52d3791fc1cebe62dccf32601a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() | |
{ | |
var pswpElement = document.querySelectorAll('.pswp')[0]; | |
var items = []; | |
$(".large-image").each(function(index) | |
{ | |
$(this).removeClass("hidden"); | |
items.push({ | |
src: $(this).attr("src"), | |
w: $(this).width(), | |
h: $(this).height() | |
}); | |
$(this).addClass("hidden"); | |
}); | |
var params = getQueryParams(document.location.toString()); | |
var currentGalleryID = params["pid"]; | |
if(currentGalleryID != null && currentGalleryID != '') | |
{ | |
var options = { | |
// optionName: 'option value' | |
// for example: | |
zoomEl: false, | |
shareEl: false, | |
index: currentGalleryID // start at first slide | |
}; | |
var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options); | |
gallery.init(); | |
} | |
$(".gallery-image").click(function(){ | |
var options = { | |
zoomEl: false, | |
shareEl: false, | |
// optionName: 'option value' | |
// for example: | |
index: parseInt($(this).attr("data-index")) // start at first slide | |
}; | |
var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options); | |
gallery.init(); | |
}) | |
// define options (if needed) | |
// Initializes and opens PhotoSwipe | |
}); | |
function getQueryParams(qs) { | |
qs = qs.split('#')[1]; | |
var params = {}, | |
tokens, | |
re = /[&]?([^=]+)=([^&]*)/g; | |
while (tokens = re.exec(qs)) { | |
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]); | |
} | |
return params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment