Skip to content

Commit

Permalink
Added back button and escape listeners for closing the full screen popup
Browse files Browse the repository at this point in the history
  • Loading branch information
amritk committed Jun 5, 2019
1 parent 16f3fe8 commit f6040b7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/FullScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ function (_ImageViewer) {
display: 'none'
}); // enable scroll

// escape listener
document.removeEventListener('keyup', _this._events.escapeListener);
// Android back button listener
document.removeEventListener('backbutton', _this._events.androidBackButtonListener);

(0, _util.removeCss)(document.querySelector('html'), 'overflow'); // remove window event

_this._events.onWindowResize();
Expand Down Expand Up @@ -101,6 +106,21 @@ function (_ImageViewer) {
this.load(imageSrc, hiResImageSrc);
} // handle window resize

// escape listener
this._events.escapeListener = (e) => {
if (e.keyCode === 27 || e.key === 'Escape') {
this.hide();
e.preventDefault();
}
}
document.addEventListener('keyup', this._events.escapeListener);

// Android back button listener
this._events.androidBackButtonListener = (e) => {
this.hide();
e.preventDefault();
}
document.addEventListener('backbutton', this._events.androidBackButtonListener);

this._events.onWindowResize = (0, _util.assignEvent)(window, 'resize', this.refresh); // disable scroll on html

Expand All @@ -124,4 +144,4 @@ function (_ImageViewer) {
}(_ImageViewer2.default);

var _default = FullScreenViewer;
exports.default = _default;
exports.default = _default;

0 comments on commit f6040b7

Please sign in to comment.