Permalink
Browse files

Added new option to the imageScaleMethod setting "fitNoUpscale". This…

… will ensure the image fits into the viewport but it won't upscale the image.
  • Loading branch information...
1 parent e763e1d commit dbf07315215aabc826f6039c0bba2d0e591e6aa5 codecomputerlove committed Jul 5, 2011
Showing with 55 additions and 32 deletions.
  1. +1 −1 src/examples/debug.html
  2. +1 −1 src/photoswipe.js
  3. +53 −30 src/slider-item-class.js
View
@@ -175,7 +175,7 @@
swipeTimeThreshold: 250,
loop: true,
slideshowDelay: 3000,
- imageScaleMethod: 'fit', // Either "fit" or "zoom"
+ imageScaleMethod: 'fit', // Either "fit", "fitNoUpscale" or "zoom"
preventHide: false,
zIndex: 1000,
backButtonHideEnabled: true,
View
@@ -65,7 +65,7 @@
swipeTimeThreshold: 250,
loop: true,
slideshowDelay: 3000,
- imageScaleMethod: 'fit', // Either "fit" or "zoom"
+ imageScaleMethod: 'fit', // Either "fit", "fitNoUpscale" or "zoom"
preventHide: false,
zIndex: 1000,
backButtonHideEnabled: true,
View
@@ -103,47 +103,70 @@
maxWidth = Util.DOM.width(this.el),
maxHeight = Util.DOM.height(this.el);
- if (this.fullSizeImage.isLandscape) {
- // Ensure the width fits the screen
- scale = maxWidth / this.fullSizeImage.naturalWidth;
- }
- else {
- // Ensure the height fits the screen
- scale = maxHeight / this.fullSizeImage.naturalHeight;
- }
-
- newWidth = Math.round(this.fullSizeImage.naturalWidth * scale);
- newHeight = Math.round(this.fullSizeImage.naturalHeight * scale);
- if (this.fullSizeImage.scaleMethod === 'zoom'){
+ if (this.fullSizeImage.scaleMethod === 'fitNoUpscale'){
- scale = 1;
- if (newHeight < maxHeight){
- scale = maxHeight /newHeight;
- }
- else if (newWidth < maxWidth){
- scale = maxWidth /newWidth;
- }
+ newWidth = this.fullSizeImage.naturalWidth;
+ newHeight = this.fullSizeImage.naturalHeight;
- if (scale !== 1) {
+ if (newWidth > maxWidth){
+ scale = maxWidth / newWidth;
newWidth = Math.round(newWidth * scale);
newHeight = Math.round(newHeight * scale);
}
+ if (newHeight > maxHeight){
+ scale = maxHeight / newHeight;
+ newHeight = Math.round(newHeight * scale);
+ newWidth = Math.round(newWidth * scale);
+ }
+
}
- else if (this.fullSizeImage.scaleMethod === 'fit') {
- // Rescale again to ensure full image fits into the viewport
- scale = 1;
- if (newWidth > maxWidth) {
- scale = maxWidth / newWidth;
+ else{
+
+ if (this.fullSizeImage.isLandscape) {
+ // Ensure the width fits the screen
+ scale = maxWidth / this.fullSizeImage.naturalWidth;
}
- else if (newHeight > maxHeight) {
- scale = maxHeight / newHeight;
+ else {
+ // Ensure the height fits the screen
+ scale = maxHeight / this.fullSizeImage.naturalHeight;
}
- if (scale !== 1) {
- newWidth = Math.round(newWidth * scale);
- newHeight = Math.round(newHeight * scale);
+
+ newWidth = Math.round(this.fullSizeImage.naturalWidth * scale);
+ newHeight = Math.round(this.fullSizeImage.naturalHeight * scale);
+
+ if (this.fullSizeImage.scaleMethod === 'zoom'){
+
+ scale = 1;
+ if (newHeight < maxHeight){
+ scale = maxHeight /newHeight;
+ }
+ else if (newWidth < maxWidth){
+ scale = maxWidth /newWidth;
+ }
+
+ if (scale !== 1) {
+ newWidth = Math.round(newWidth * scale);
+ newHeight = Math.round(newHeight * scale);
+ }
+
+ }
+ else if (this.fullSizeImage.scaleMethod === 'fit') {
+ // Rescale again to ensure full image fits into the viewport
+ scale = 1;
+ if (newWidth > maxWidth) {
+ scale = maxWidth / newWidth;
+ }
+ else if (newHeight > maxHeight) {
+ scale = maxHeight / newHeight;
+ }
+ if (scale !== 1) {
+ newWidth = Math.round(newWidth * scale);
+ newHeight = Math.round(newHeight * scale);
+ }
}
+
}
newTop = ((maxHeight - newHeight) / 2) + 'px';

0 comments on commit dbf0731

Please sign in to comment.