Skip to content

Commit

Permalink
fix: prevent zoom on mobile when handleTouch is set to false (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
sherwinski authored Aug 2, 2019
1 parent e982561 commit d1ea511
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/js/Trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export default class Trigger {
return this.settings.zoomPane.isShowing;
}

_preventDefault(event) {
event.preventDefault();
}

_bindEvents() {
this.settings.el.addEventListener("mouseenter", this._handleEntry, false);
this.settings.el.addEventListener("mouseleave", this._hide, false);
Expand All @@ -66,6 +70,10 @@ export default class Trigger {
this.settings.el.addEventListener("touchstart", this._handleEntry, false);
this.settings.el.addEventListener("touchend", this._hide, false);
this.settings.el.addEventListener("touchmove", this._handleMovement, false);
} else {
this.settings.el.addEventListener("touchstart", this._preventDefault, false);
this.settings.el.addEventListener("touchend", this._preventDefault, false);
this.settings.el.addEventListener("touchmove", this._preventDefault, false);
}
}

Expand All @@ -78,6 +86,10 @@ export default class Trigger {
this.settings.el.removeEventListener("touchstart", this._handleEntry, false);
this.settings.el.removeEventListener("touchend", this._hide, false);
this.settings.el.removeEventListener("touchmove", this._handleMovement, false);
} else {
this.settings.el.removeEventListener("touchstart", this._preventDefault, false);
this.settings.el.removeEventListener("touchend", this._preventDefault, false);
this.settings.el.removeEventListener("touchmove", this._preventDefault, false);
}
}

Expand Down
24 changes: 24 additions & 0 deletions test/testTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,28 @@ describe("Trigger", () => {

expect(called).toBe(true);
});

it("executes touchstart on mobile when handleTouch is set to true", () => {
const opts = triggerOptions();
opts.handleTouch = true;
const spy = spyOn(Trigger.prototype, "_handleEntry");
const trigger = new Trigger(opts);

const event = new Event("touchstart");

trigger.settings.el.dispatchEvent(event);
expect(spy).toHaveBeenCalled();
});

it("does not execute touchstart on mobile when handleTouch is set to false", () => {
const opts = triggerOptions();
opts.handleTouch = false;
const spy = spyOn(Trigger.prototype, "_handleEntry");
const trigger = new Trigger(opts);

const event = new Event("touchstart");

trigger.settings.el.dispatchEvent(event);
expect(spy).not.toHaveBeenCalled();
});
});

0 comments on commit d1ea511

Please sign in to comment.