Browse Source

Fix #108

pull/111/head
Jānis Skarnelis 4 years ago
parent
commit
34e5eb060c
  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. 6
      src/Carousel/Carousel.js
  8. 38
      src/Fancybox/Fancybox.js
  9. 6
      src/shared/utils/isScrollable.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

6
src/Carousel/Carousel.js

@ -200,7 +200,7 @@ export class Carousel extends Base {
let viewportWidth = Math.max(this.$track.offsetWidth, round(this.$track.getBoundingClientRect().width)); let viewportWidth = Math.max(this.$track.offsetWidth, round(this.$track.getBoundingClientRect().width));
let viewportStyles = window.getComputedStyle(this.$track); let viewportStyles = getComputedStyle(this.$track);
viewportWidth = viewportWidth - (parseFloat(viewportStyles.paddingLeft) + parseFloat(viewportStyles.paddingRight)); viewportWidth = viewportWidth - (parseFloat(viewportStyles.paddingLeft) + parseFloat(viewportStyles.paddingRight));
this.contentWidth = contentWidth; this.contentWidth = contentWidth;
@ -505,8 +505,8 @@ export class Carousel extends Base {
const preload = this.option("preload"); const preload = this.option("preload");
const infinite = this.option("infiniteX", this.option("infinite")); const infinite = this.option("infiniteX", this.option("infinite"));
const paddingLeft = parseFloat(window.getComputedStyle(this.$viewport, null).getPropertyValue("padding-left")); const paddingLeft = parseFloat(getComputedStyle(this.$viewport, null).getPropertyValue("padding-left"));
const paddingRight = parseFloat(window.getComputedStyle(this.$viewport, null).getPropertyValue("padding-right")); const paddingRight = parseFloat(getComputedStyle(this.$viewport, null).getPropertyValue("padding-right"));
// Check visibility of each slide // Check visibility of each slide
this.slides.forEach((slide) => { this.slides.forEach((slide) => {

38
src/Fancybox/Fancybox.js

@ -1,4 +1,3 @@
// var global = global || window;
import { extend } from "../shared/utils/extend.js"; import { extend } from "../shared/utils/extend.js";
import { canUseDOM } from "../shared/utils/canUseDOM.js"; import { canUseDOM } from "../shared/utils/canUseDOM.js";
@ -11,6 +10,7 @@ import { Plugins } from "./plugins/index.js";
// Default language // Default language
import en from "./l10n/en.js"; import en from "./l10n/en.js";
// Default settings
const defaults = { const defaults = {
// Index of active slide on the start // Index of active slide on the start
startIndex: 0, startIndex: 0,
@ -94,6 +94,10 @@ const defaults = {
l10n: en, l10n: en,
}; };
// Object that contains all active instances of Fancybox
const instances = {};
// Number of Fancybox instances created, it is used to generate new instance "id"
let called = 0; let called = 0;
class Fancybox extends Base { class Fancybox extends Base {
@ -126,6 +130,8 @@ class Fancybox extends Base {
this.attachEvents(); this.attachEvents();
instances[this.id] = this;
// "prepare" event will trigger the creation of additional layout elements, such as thumbnails and toolbar // "prepare" event will trigger the creation of additional layout elements, such as thumbnails and toolbar
this.trigger("prepare"); this.trigger("prepare");
@ -486,7 +492,7 @@ class Fancybox extends Base {
} }
// Skip if text is selected // Skip if text is selected
if (window.getSelection().toString().length) { if (getSelection().toString().length) {
return; return;
} }
@ -836,7 +842,7 @@ class Fancybox extends Base {
$content.classList.add("fancybox__content"); $content.classList.add("fancybox__content");
// Make sure that content is not hidden and will be visible // Make sure that content is not hidden and will be visible
if ($content.style.display === "none" || window.getComputedStyle($content).getPropertyValue("display") === "none") { if ($content.style.display === "none" || getComputedStyle($content).getPropertyValue("display") === "none") {
$content.style.display = slide.display || this.option("defaultDisplay") || "flex"; $content.style.display = slide.display || this.option("defaultDisplay") || "flex";
} }
@ -1084,7 +1090,7 @@ class Fancybox extends Base {
// First, stop further execution if this instance is already closing // First, stop further execution if this instance is already closing
// (this can happen if, for example, user clicks close button multiple times really fast) // (this can happen if, for example, user clicks close button multiple times really fast)
if (["closing", "customClosing", "destroy"].indexOf(this.state) > -1) { if (["closing", "customClosing", "destroy"].includes(this.state)) {
return; return;
} }
@ -1172,6 +1178,8 @@ class Fancybox extends Base {
} }
} }
delete instances[this.id];
const nextInstance = Fancybox.getInstance(); const nextInstance = Fancybox.getInstance();
if (nextInstance) { if (nextInstance) {
@ -1446,23 +1454,21 @@ class Fancybox extends Base {
* @param {String|Numeric} [id] - Optional instance identifier * @param {String|Numeric} [id] - Optional instance identifier
*/ */
static getInstance(id) { static getInstance(id) {
let nodes = [];
if (id) { if (id) {
nodes = [document.getElementById(`fancybox-${id}`)]; return instances[id];
} else {
nodes = Array.from(document.querySelectorAll(".fancybox__container")).reverse();
} }
for (const $container of nodes) { const instance = Object.values(instances)
const instance = $container && $container.Fancybox; .reverse()
.find((instance) => {
if (!["closing", "customClosing", "destroy"].includes(instance.state)) {
return instance;
}
if (instance && instance.state !== "closing" && instance.state !== "customClosing") { return false;
return instance; });
}
}
return null; return instance || null;
} }
/** /**

6
src/shared/utils/isScrollable.js

@ -4,8 +4,8 @@
* @returns {Boolean} * @returns {Boolean}
*/ */
export const hasScrollbars = function (node) { export const hasScrollbars = function (node) {
const overflowY = window.getComputedStyle(node)["overflow-y"], const overflowY = getComputedStyle(node)["overflow-y"],
overflowX = window.getComputedStyle(node)["overflow-x"], overflowX = getComputedStyle(node)["overflow-x"],
vertical = (overflowY === "scroll" || overflowY === "auto") && Math.abs(node.scrollHeight - node.clientHeight) > 1, vertical = (overflowY === "scroll" || overflowY === "auto") && Math.abs(node.scrollHeight - node.clientHeight) > 1,
horizontal = (overflowX === "scroll" || overflowX === "auto") && Math.abs(node.scrollWidth - node.clientWidth) > 1; horizontal = (overflowX === "scroll" || overflowX === "auto") && Math.abs(node.scrollWidth - node.clientWidth) > 1;
@ -18,7 +18,7 @@ export const hasScrollbars = function (node) {
* @returns {Boolean} * @returns {Boolean}
*/ */
export const isScrollable = function (node) { export const isScrollable = function (node) {
if (!node || node === document.body) { if (!node || !(typeof node === "object" && node instanceof Element) || node === document.body) {
return false; return false;
} }

Loading…
Cancel
Save