Skip to content

Commit

Permalink
Merged pull request #132. Added double click to zoom for desktop brow…
Browse files Browse the repository at this point in the history
…sers - Thanks to coderkan
  • Loading branch information
root committed Mar 24, 2019
1 parent d6c271c commit 8024c27
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ $add-vendor-prefixes: true !default;


### Changelog
**1.17.0 - Merged pull request #132. Added double click to zoom for desktop browsers - Thanks to coderkan**
**1.16.3 - Merged pull request #126,#127 - Thanks to jieter**
**1.16.2 - Added featured #124 - Add a class to html element if lightbox is open**
**1.16.1 - Fixed pinch to zoom offset error on scrolling #123**
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simplelightbox",
"version": "1.16.3",
"version": "1.17.0",
"homepage": "http://simplelightbox.com/",
"authors": [
"André Rinas <info@andrerinas.de> (https://www.andrerinas.de)"
Expand Down
71 changes: 70 additions & 1 deletion dist/simple-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
By André Rinas, www.andrerinas.de
Documentation, www.simplelightbox.de
Available for use under the MIT License
1.16.3
1.17.0
*/
;( function( $, window, document, undefined )
{
Expand Down Expand Up @@ -418,7 +418,19 @@ $.fn.simpleLightbox = function( options )
}
e = e.originalEvent;
if(e.type == 'mousedown') {
initialPointerOffsetX = e.clientX;
initialPointerOffsetY = e.clientY;
containerHeight = image.height();
containerWidth = image.width();
imgHeight = curImg.height();
imgWidth = curImg.width();
containerOffsetX = image.position().left;
containerOffsetY = image.position().top;

initialOffsetX = parseFloat(curImg.data('translate-x'));
initialOffsetY = parseFloat(curImg.data('translate-y'));

capture = true;
} else {
touchCount = e.touches.length;
initialPointerOffsetX = e.touches[0].clientX;
Expand Down Expand Up @@ -544,6 +556,31 @@ $.fn.simpleLightbox = function( options )
zoomPanElement(targetOffsetX + "px", targetOffsetY + "px", targetScale);
}
}
/* Mouse Move implementation */
if(e.type == 'mousemove' && mousedown){
if(e.type == 'touchmove') return true;
if(capture === false) return false;
pointerOffsetX = e.clientX;
pointerOffsetY = e.clientY;
targetScale = initialScale;
limitOffsetX = ((imgWidth * targetScale) - containerWidth) / 2;
limitOffsetY = ((imgHeight * targetScale) - containerHeight) / 2;
targetOffsetX = (imgWidth * targetScale) <= containerWidth ? 0 : minMax(pointerOffsetX - (initialPointerOffsetX - initialOffsetX), limitOffsetX * (-1), limitOffsetX);
targetOffsetY = (imgHeight * targetScale) <= containerHeight ? 0 : minMax(pointerOffsetY - (initialPointerOffsetY - initialOffsetY), limitOffsetY * (-1), limitOffsetY);

if (Math.abs(targetOffsetX) === Math.abs(limitOffsetX)) {
initialOffsetX = targetOffsetX;
initialPointerOffsetX = pointerOffsetX;
}

if (Math.abs(targetOffsetY) === Math.abs(limitOffsetY)) {
initialOffsetY = targetOffsetY;
initialPointerOffsetY = pointerOffsetY;
}

setZoomData(initialScale,targetOffsetX,targetOffsetY);
zoomPanElement(targetOffsetX + "px", targetOffsetY + "px", targetScale);
}
if(!zoomed) {
swipeEnd = e.pageX || e.touches[ 0 ].pageX;
swipeYEnd = e.pageY || e.touches[ 0 ].pageY;
Expand Down Expand Up @@ -597,6 +634,38 @@ $.fn.simpleLightbox = function( options )
close();
}
}
})
/** Detect Double click on image*/
.on( 'dblclick', function(e)
{
initialPointerOffsetX = e.clientX;
initialPointerOffsetY = e.clientY;
containerHeight = image.height();
containerWidth = image.width();
imgHeight = curImg.height();
imgWidth = curImg.width();
containerOffsetX = image.position().left;
containerOffsetY = image.position().top;

curImg.addClass('sl-transition');
if(!zoomed) {
initialScale = options.doubleTapZoom;
setZoomData(0,0, initialScale);
zoomPanElement(0 + "px", 0 + "px", initialScale);
$('.sl-caption').fadeOut(200);
zoomed = true;
} else {
initialScale = 1;
setZoomData(0,0,initialScale);
zoomPanElement(0 + "px", 0 + "px", initialScale);
zoomed = false;
}

setTimeout(function(){
curImg.removeClass('sl-transition');
}, 200);
capture = true;
return false;
});
},
removeEvents = function(){
Expand Down
4 changes: 2 additions & 2 deletions dist/simple-lightbox.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simplelightbox",
"version": "1.16.3",
"version": "1.17.0",
"description": "Touch-friendly image lightbox for mobile and desktop with jQuery",
"main": "dist/simple-lightbox.js",
"style": "dist/simplelightbox.scss",
Expand Down

0 comments on commit 8024c27

Please sign in to comment.