diff options
Diffstat (limited to 'recipes/basecamp')
-rw-r--r-- | recipes/basecamp/webview.js | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/recipes/basecamp/webview.js b/recipes/basecamp/webview.js index e7b7dde..16eced3 100644 --- a/recipes/basecamp/webview.js +++ b/recipes/basecamp/webview.js | |||
@@ -1,9 +1,10 @@ | |||
1 | const _path = _interopRequireDefault(require('path')); | 1 | const _path = _interopRequireDefault(require('path')); |
2 | 2 | ||
3 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | 3 | function _interopRequireDefault(obj) { |
4 | return obj && obj.__esModule ? obj : { default: obj }; | ||
5 | } | ||
4 | 6 | ||
5 | module.exports = (Ferdi) => { | 7 | module.exports = Ferdi => { |
6 | let updates = 0; | ||
7 | const modal = document.createElement('div'); | 8 | const modal = document.createElement('div'); |
8 | 9 | ||
9 | const waitFor = (condition, callback) => { | 10 | const waitFor = (condition, callback) => { |
@@ -16,13 +17,11 @@ module.exports = (Ferdi) => { | |||
16 | function showModal(text) { | 17 | function showModal(text) { |
17 | show(modal); | 18 | show(modal); |
18 | modal.querySelector('p').innerHTML = text; | 19 | modal.querySelector('p').innerHTML = text; |
19 | updates += 1; | ||
20 | } | 20 | } |
21 | 21 | ||
22 | function hideModal() { | 22 | function hideModal() { |
23 | hide(modal); | 23 | hide(modal); |
24 | modal.querySelector('p').innerHTML = ''; | 24 | modal.querySelector('p').innerHTML = ''; |
25 | updates -= 1; | ||
26 | } | 25 | } |
27 | 26 | ||
28 | // Replace window.alert to hide alerts in Ferdi | 27 | // Replace window.alert to hide alerts in Ferdi |
@@ -41,11 +40,19 @@ module.exports = (Ferdi) => { | |||
41 | } | 40 | } |
42 | 41 | ||
43 | modal.id = 'franz-modal'; | 42 | modal.id = 'franz-modal'; |
44 | modal.innerHTML = '<div class="modal-content"><span class="close">×</span><p></p></div>'; | 43 | modal.innerHTML = |
44 | '<div class="modal-content"><span class="close">×</span><p></p></div>'; | ||
45 | modal.querySelector('.close').addEventListener('click', hideModal); | 45 | modal.querySelector('.close').addEventListener('click', hideModal); |
46 | waitFor(() => document.body, () => document.body.appendChild(modal)); | 46 | waitFor( |
47 | 47 | () => document.body, | |
48 | document.addEventListener('keydown', (e) => { if (e.keyCode === 27) { hideModal(); } }); | 48 | () => document.body.appendChild(modal), |
49 | ); | ||
50 | |||
51 | document.addEventListener('keydown', e => { | ||
52 | if (e.key === 'Escape') { | ||
53 | hideModal(); | ||
54 | } | ||
55 | }); | ||
49 | 56 | ||
50 | Ferdi.injectCSS(_path.default.join(__dirname, 'css', 'modal.css')); | 57 | Ferdi.injectCSS(_path.default.join(__dirname, 'css', 'modal.css')); |
51 | }; | 58 | }; |