Browse Source

Add `data-width`, `data-height` support for images

pull/188/head
Jānis Skarnelis 4 years ago
parent
commit
270ffbc29b
  1. 2
      dist/carousel.esm.js
  2. 2
      dist/carousel.umd.js
  3. 2
      dist/fancybox.esm.js
  4. 2
      dist/fancybox.umd.js
  5. 2
      dist/panzoom.esm.js
  6. 2
      dist/panzoom.umd.js
  7. 9
      src/Fancybox/plugins/Image/Image.js
  8. 19
      src/Panzoom/Panzoom.js

2
dist/carousel.esm.js

File diff suppressed because one or more lines are too long

2
dist/carousel.umd.js

File diff suppressed because one or more lines are too long

2
dist/fancybox.esm.js

File diff suppressed because one or more lines are too long

2
dist/fancybox.umd.js

File diff suppressed because one or more lines are too long

2
dist/panzoom.esm.js

File diff suppressed because one or more lines are too long

2
dist/panzoom.umd.js

File diff suppressed because one or more lines are too long

9
src/Fancybox/plugins/Image/Image.js

@ -287,6 +287,9 @@ export class Image {
viewport: slide.$wrap, viewport: slide.$wrap,
content: slide.$image, content: slide.$image,
width: slide._width,
height: slide._height,
wrapInner: false, wrapInner: false,
// Allow to select caption text // Allow to select caption text
@ -370,7 +373,7 @@ export class Image {
return { return {
top: shiftedTop, top: shiftedTop,
left: shiftedLeft, left: shiftedLeft,
scale: thumbRect.width / contentWidth, scale: contentWidth && thumbWidth ? thumbWidth / contentWidth : 1,
opacity: opacity, opacity: opacity,
}; };
} }
@ -386,6 +389,10 @@ export class Image {
return false; return false;
} }
if (slide.Panzoom && !slide.Panzoom.content.width) {
return false;
}
if (!fancybox.option("Image.zoom") || fancybox.option("Image.fit") !== "contain") { if (!fancybox.option("Image.zoom") || fancybox.option("Image.fit") !== "contain") {
return false; return false;
} }

19
src/Panzoom/Panzoom.js

@ -181,8 +181,8 @@ export class Panzoom extends Base {
this.content = { this.content = {
// Full content dimensions (naturalWidth/naturalHeight for images) // Full content dimensions (naturalWidth/naturalHeight for images)
origHeight: 0,
origWidth: 0, origWidth: 0,
origHeight: 0,
// Current dimensions of the content // Current dimensions of the content
width: 0, width: 0,
@ -636,16 +636,19 @@ export class Panzoom extends Base {
const $content = this.$content; const $content = this.$content;
const $viewport = this.$viewport; const $viewport = this.$viewport;
const contentIsImage = this.$content instanceof HTMLImageElement; const contentIsImage = $content instanceof HTMLImageElement;
const contentIsZoomable = this.option("zoom"); const contentIsZoomable = this.option("zoom");
const shouldResizeParent = this.option("resizeParent", contentIsZoomable); const shouldResizeParent = this.option("resizeParent", contentIsZoomable);
let origWidth = getFullWidth(this.$content); let width = this.option("width");
let origHeight = getFullHeight(this.$content); let height = this.option("height");
let origWidth = width || getFullWidth($content);
let origHeight = height || getFullHeight($content);
Object.assign($content.style, { Object.assign($content.style, {
width: "", width: width ? `${width}px` : "",
height: "", height: height ? `${height}px` : "",
maxWidth: "", maxWidth: "",
maxHeight: "", maxHeight: "",
}); });
@ -659,8 +662,8 @@ export class Panzoom extends Base {
origWidth = round(origWidth * ratio); origWidth = round(origWidth * ratio);
origHeight = round(origHeight * ratio); origHeight = round(origHeight * ratio);
let width = origWidth; width = origWidth;
let height = origHeight; height = origHeight;
const contentRect = $content.getBoundingClientRect(); const contentRect = $content.getBoundingClientRect();
const viewportRect = $viewport.getBoundingClientRect(); const viewportRect = $viewport.getBoundingClientRect();

Loading…
Cancel
Save