Skip to content
Snippets Groups Projects
Commit dd5baec9 authored by Julian Pustkuchen's avatar Julian Pustkuchen
Browse files

Issue #2891337 by amanire, Anybody: Zoom animation (Drupal 8)

parent 0f32c498
No related branches found
Tags 8.x-2.4
No related merge requests found
......@@ -15,12 +15,12 @@
this.photoSwipeOptions = settings.photoswipe ? settings.photoswipe.options : {};
// First ensure all photoswipe photos are in a photoswipe-gallery wrapper:
var $imagesWithoutGalleries = $('a.photoswipe', context).filter(function(elem) {
var $imagesWithoutGalleries = $('a.photoswipe', context).filter(function (elem) {
return !$(this).parents('.photoswipe-gallery').length;
});
if ($imagesWithoutGalleries.length) {
// We have no galleries just individual images.
$imagesWithoutGalleries.each(function(index) {
$imagesWithoutGalleries.each(function (index) {
$imageLink = $(this);
// Add the wrapper and indicate that it's an automatic fallback:
$imageLink.wrap('<span class="photoswipe-gallery photoswipe-gallery--fallback-wrapper"></span>');
......@@ -30,7 +30,7 @@
var $galleries = $('.photoswipe-gallery', context);
if ($galleries.length) {
// if body haven't special container for show photoswipe gallery append it.
if('container' in settings.photoswipe && !$('.pswp').length){
if ('container' in settings.photoswipe && !$('.pswp').length) {
$('body').append(settings.photoswipe.container);
}
......@@ -46,8 +46,8 @@
// Parse URL and open gallery if it contains #&pid=3&gid=1
var hashData = this.parseHash();
if(hashData.pid > 0 && hashData.gid > 0) {
this.openPhotoSwipe(hashData.pid - 1 , $($galleries[hashData.gid - 1]));
if (hashData.pid > 0 && hashData.gid > 0) {
this.openPhotoSwipe(hashData.pid - 1, $($galleries[hashData.gid - 1]));
}
},
/**
......@@ -56,7 +56,7 @@
* Code taken from http://photoswipe.com/documentation/getting-started.html
* and adjusted accordingly.
*/
onThumbnailsClick: function(e) {
onThumbnailsClick: function (e) {
e = e || window.event;
var $clickedGallery = $(this);
var eTarget = e.target || e.srcElement;
......@@ -82,7 +82,7 @@
* Code taken from http://photoswipe.com/documentation/getting-started.html
* and adjusted accordingly.
*/
openPhotoSwipe: function(index, galleryElement, options) {
openPhotoSwipe: function (index, galleryElement, options) {
var pswpElement = $('.pswp')[0];
var items = [];
options = options || Drupal.behaviors.photoswipe.photoSwipeOptions;
......@@ -90,13 +90,14 @@
var images = galleryElement.find('a.photoswipe');
images.each(function (index) {
var $image = $(this);
size = $image.data('size') ? $image.data('size').split('x') : ['',''];
size = $image.data('size') ? $image.data('size').split('x') : ['', ''];
items.push(
{
src : $image.attr('href'),
src: $image.attr('href'),
w: size[0],
h: size[1],
title : $image.data('overlay-title')
title: $image.data('overlay-title'),
msrc: $image.find('img').attr('src')
}
);
})
......@@ -106,6 +107,17 @@
// define gallery index (for URL)
options.galleryUID = galleryElement.data('pswp-uid');
// Add zoom animation function:
options.getThumbBoundsFn = function (index) {
var tn = galleryElement.find('a.photoswipe:eq(' + index + ') img');
if (tn.length == 0) {
tn = galleryElement.find('a.photoswipe:eq(0) img');
}
var tw = tn.width();
var tpos = tn.offset();
return { x: tpos.left, y: tpos.top, w: tw };
}
// Pass data to PhotoSwipe and initialize it
var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
gallery.init();
......@@ -117,9 +129,9 @@
* Code taken from http://photoswipe.com/documentation/getting-started.html
* and adjusted accordingly.
*/
parseHash: function() {
parseHash: function () {
var hash = window.location.hash.substring(1),
params = {};
params = {};
if (hash.length < 5) {
return params;
......@@ -137,11 +149,11 @@
params[pair[0]] = pair[1];
}
if(params.gid) {
if (params.gid) {
params.gid = parseInt(params.gid, 10);
}
if(!params.hasOwnProperty('pid')) {
if (!params.hasOwnProperty('pid')) {
return params;
}
params.pid = parseInt(params.pid, 10);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment