From 669fe842cb857465ba6a81254f0db682349c4919 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Thu, 22 Oct 2020 00:46:58 +0800 Subject: [PATCH] automatically close dialog when press esc in keyboard or back button in mobile device --- src/mobile-main.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/mobile-main.js b/src/mobile-main.js index f313d58f..4c2bc3c1 100644 --- a/src/mobile-main.js +++ b/src/mobile-main.js @@ -79,4 +79,21 @@ new Vue({ el: '#app', i18n: i18n, render: h => h(App), + mounted: function () { + const app = this.$f7; + + window.addEventListener('popstate', () => { + if (document.querySelectorAll('.modal-in').length > 0) { + app.dialog.close(); + } + }, false); + + document.addEventListener('keydown', (event) => { + if (event.key === 'Escape' || event.key === 'Esc' || event.keyCode === 27 || event.which === 27) { + if (document.querySelectorAll('.modal-in').length > 0) { + app.dialog.close(); + } + } + }, false); + } });