Created
November 23, 2016 11:16
-
-
Save ttomdewit/dca66c20ca1e79710ba293bd7a19c8b0 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
function photoswipe(gallerySelector) { | |
function parseElements(el) { | |
var elements = $(el).children('.gallery__item'), | |
numberOfElements = elements.length, | |
items = [], | |
slideElement, | |
linkElement, | |
size, | |
item; | |
for (var i = 0; i < numberOfElements; i++) { | |
var slideElement = elements[i]; | |
var image = $(slideElement).data('source'); | |
var size = $(slideElement).data('size').split('x'); | |
item = { | |
src: image, | |
w: parseInt(size[0], 10), | |
h: parseInt(size[1], 10) | |
} | |
items.push(item); | |
} | |
return items; | |
}; | |
function openPhotoSwipe() { | |
var pswpElement = $('.pswp')[0], | |
gallery, | |
options, | |
items = parseElements(gallerySelector); | |
options = {}; | |
gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options); | |
gallery.init(); | |
} | |
$('.gallery__item').click(function (e) { | |
e.preventDefault(); | |
var index = $(this).data('index'); | |
openPhotoSwipe(); | |
}); | |
} |
Author
ttomdewit
commented
Nov 25, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment