Skip to content

Commit

Permalink
fix: document undefined in no browser environment
Browse files Browse the repository at this point in the history
  • Loading branch information
miljan-aleksic authored and luqven committed May 20, 2021
1 parent 29664a6 commit 23305b5
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/js/ZoomPane.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import throwIfMissing from "./util/throwIfMissing";
import { addClasses, removeClasses } from "./util/dom";

// All officially-supported browsers have this, but it's easy to
// account for, just in case.
const divStyle = document.createElement("div").style;

const HAS_ANIMATION =
typeof document === "undefined" ? false : "animation" in divStyle || "webkitAnimation" in divStyle;

export default class ZoomPane {
constructor(options = {}) {
// All officially-supported browsers have this, but it's easy to
// account for, just in case.
this.HAS_ANIMATION = false;
if (typeof document !== "undefined") {
const divStyle = document.createElement("div").style;
this.HAS_ANIMATION = "animation" in divStyle || "webkitAnimation" in divStyle;
}

this._completeShow = this._completeShow.bind(this);
this._completeHide = this._completeHide.bind(this);
this._handleLoad = this._handleLoad.bind(this);
Expand Down Expand Up @@ -197,7 +198,7 @@ export default class ZoomPane {
this._showInContainer();
}

if (HAS_ANIMATION) {
if (this.HAS_ANIMATION) {
this.el.addEventListener("animationend", this._completeShow, false);
this.el.addEventListener("webkitAnimationEnd", this._completeShow, false);
addClasses(this.el, this.openingClasses);
Expand All @@ -217,7 +218,7 @@ export default class ZoomPane {
this._removeListenersAndResetClasses();
this.isShowing = false;

if (HAS_ANIMATION) {
if (this.HAS_ANIMATION) {
this.el.addEventListener("animationend", this._completeHide, false);
this.el.addEventListener("webkitAnimationEnd", this._completeHide, false);
addClasses(this.el, this.closingClasses);
Expand Down

0 comments on commit 23305b5

Please sign in to comment.