Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save masterkitano/1abc4c52d3791fc1cebe62dccf32601a to your computer and use it in GitHub Desktop.
Save masterkitano/1abc4c52d3791fc1cebe62dccf32601a to your computer and use it in GitHub Desktop.
$(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