Skip to content

Commit

Permalink
Enable desktop sliding for PhotoSwipe 5
Browse files Browse the repository at this point in the history
  • Loading branch information
arnowelzel committed Nov 25, 2023
1 parent 221983d commit bdfdc0d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
21 changes: 20 additions & 1 deletion assets/ps5/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ let lbwpsInit = function(domUpdate) {
options.history = lbwpsOptions.history === '1';
options.zoomEl = lbwpsOptions.show_zoom === '1';
options.tapToToggleControls = lbwpsOptions.taptotoggle === '1';
options.desktopSlider = lbwpsOptions.desktop_slider === '1';
*/


const lightbox = new PhotoSwipeLightbox(options);
lightbox.on('destroy', () => {
const pswpElements = document.getElementsByClassName('pswp__scroll-wrap');
Expand Down Expand Up @@ -405,6 +405,25 @@ let lbwpsInit = function(domUpdate) {
);
}

// Add sliding in desktop mode
options.desktopSlider = lbwpsOptions.desktop_slider === '1';

if (options.desktopSlider) {
const lbwpsGoTo = (index, animate = false) => {
const pwsp = lightbox.pswp;
index = pwsp.getLoopedIndex(index);
const indexChanged = pwsp.mainScroll.moveIndexBy(index - pwsp.potentialIndex, animate);

if (indexChanged) {
pwsp.dispatch('afterGoto');
}
}
lightbox.on('uiRegister', () => {
lightbox.pswp.next = () => lbwpsGoTo(lightbox.pswp.potentialIndex + 1, true);
lightbox.pswp.prev = () => lbwpsGoTo(lightbox.pswp.potentialIndex - 1, true);
});
}

lightbox.init();
if (lbwpsOptions.hide_scrollbars === '1') {
hideScrollbar();
Expand Down
2 changes: 2 additions & 0 deletions assets/ps5/frontend.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lightbox-photoswipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Lightbox with PhotoSwipe
Plugin URI: https://wordpress.org/plugins/lightbox-photoswipe/
Description: Lightbox with PhotoSwipe
Version: 5.0.44
Version: 5.1.0
Author: Arno Welzel
Author URI: http://arnowelzel.de
Text Domain: lightbox-photoswipe
Expand Down
9 changes: 8 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: awelzel
Tags: attachments, images, gallery, lightbox, fancybox, photoswipe
Requires at least: 5.3
Tested up to: 6.3
Stable tag: 5.0.44
Stable tag: 5.1.0
Donate link: https://paypal.me/ArnoWelzel
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -219,6 +219,13 @@ If you change any of the stylesheets or frontend scripts in `src/js` or `src/lib

== Changelog ==

= 5.1.0 =

PhotoSwipe 5 integration:

* Updated PhtooSwipe to version 5.4.2.
* Added desktop sliding similar to PhotoSwipe 4.

= 5.0.44 =

* Fixed a compatibility issue with WPML. Images should now also be recognized as "local" when they are used on a translated version of the website.
Expand Down
2 changes: 1 addition & 1 deletion src/LightboxPhotoSwipe/LightboxPhotoSwipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class LightboxPhotoSwipe
{
const VERSION = '5.0.44';
const VERSION = '5.1.0';
const SLUG = 'lightbox-photoswipe';
const META_VERSION = '12';
const CACHE_EXPIRE_IMG_DETAILS = 86400;
Expand Down
4 changes: 2 additions & 2 deletions templates/options-tab5.inc.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div id="lbwps-tab-5" style="display:none;">
<div>
<table class="form-table">
<tr class="lbwps-ver4">
<tr>
<th scope="row">
<?php echo __('General', 'lightbox-photoswipe'); ?>
</th>
<td>
<label class="lbwps-ver4"><?php $this->uiControlCheckbox('fulldesktop'); ?> <?php echo __('Full picture size in desktop view', 'lightbox-photoswipe'); ?></label><br>
<label class="lbwps-ver4"><?php $this->uiControlCheckbox('fulldesktop'); ?> <?php echo __('Full picture size in desktop view', 'lightbox-photoswipe'); ?></label><br class="lbwps-ver4">
<label><?php $this->uiControlCheckbox('desktop_slider'); ?> <?php echo __('Use slide animation when switching images in desktop view', 'lightbox-photoswipe'); ?></label><br>
<label><?php $this->uiControlCheckbox('close_on_click'); ?> <?php echo __('Close the lightbox by clicking outside the image', 'lightbox-photoswipe'); ?></label>
</td>
Expand Down

0 comments on commit bdfdc0d

Please sign in to comment.