From f6040b7593528115fcd5dbf966cd849a15c6a810 Mon Sep 17 00:00:00 2001 From: Amrit Kahlon Date: Wed, 5 Jun 2019 11:32:24 -0700 Subject: [PATCH] Added back button and escape listeners for closing the full screen popup --- lib/FullScreen.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/FullScreen.js b/lib/FullScreen.js index 296f02f..0f1b2f7 100644 --- a/lib/FullScreen.js +++ b/lib/FullScreen.js @@ -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(); @@ -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 @@ -124,4 +144,4 @@ function (_ImageViewer) { }(_ImageViewer2.default); var _default = FullScreenViewer; -exports.default = _default; \ No newline at end of file +exports.default = _default;