Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Add zoomFactor option to control max zoom #2155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
// If opacity is "auto", then opacity will be changed if image and thumbnail have different aspect ratios
zoomOpacity: "auto",

// maximum zoom factor
zoomFactor: 1.0,

// Transition effect between slides
//
// Possible values:
Expand Down Expand Up @@ -1242,12 +1245,13 @@

scaleToActual: function(x, y, duration) {
var self = this,
opts = self.current ? self.current.opts : self.opts,
current = self.current,
$content = current.$content,
canvasWidth = $.fancybox.getTranslate(current.$slide).width,
canvasHeight = $.fancybox.getTranslate(current.$slide).height,
newImgWidth = current.width,
newImgHeight = current.height,
newImgWidth = current.width * opts.zoomFactor,
newImgHeight = current.height * opts.zoomFactor,
imgPos,
posX,
posY,
Expand Down Expand Up @@ -1594,6 +1598,7 @@

isZoomable: function() {
var self = this,
opts = self.current ? self.current.opts : self.opts,
current = self.current,
fitPos;

Expand All @@ -1607,7 +1612,7 @@

fitPos = self.getFitPos(current);

if (fitPos && (current.width > fitPos.width || current.height > fitPos.height)) {
if (fitPos && (current.width * opts.zoomFactor > fitPos.width || current.height * opts.zoomFactor > fitPos.height)) {
return true;
}
}
Expand All @@ -1620,15 +1625,16 @@

isScaledDown: function(nextWidth, nextHeight) {
var self = this,
opts = self.current ? self.current.opts : self.opts,
rez = false,
current = self.current,
$content = current.$content;

if (nextWidth !== undefined && nextHeight !== undefined) {
rez = nextWidth < current.width && nextHeight < current.height;
rez = nextWidth < current.width * opts.zoomFactor && nextHeight < current.height * opts.zoomFactor;
} else if ($content) {
rez = $.fancybox.getTranslate($content);
rez = rez.width < current.width && rez.height < current.height;
rez = rez.width < current.width * opts.zoomFactor && rez.height < current.height * opts.zoomFactor;
}

return rez;
Expand Down