diff options
Diffstat (limited to 'recipes/franz-custom-website/webview.js')
-rw-r--r-- | recipes/franz-custom-website/webview.js | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/recipes/franz-custom-website/webview.js b/recipes/franz-custom-website/webview.js index 072fed5..18f16a3 100644 --- a/recipes/franz-custom-website/webview.js +++ b/recipes/franz-custom-website/webview.js | |||
@@ -1,30 +1,36 @@ | |||
1 | const _path = _interopRequireDefault(require('path')); | ||
2 | |||
3 | function _interopRequireDefault(obj) { | 1 | function _interopRequireDefault(obj) { |
4 | return obj && obj.__esModule ? obj : { default: obj }; | 2 | return obj && obj.__esModule ? obj : { default: obj }; |
5 | } | 3 | } |
6 | 4 | ||
5 | const _path = _interopRequireDefault(require('path')); | ||
6 | |||
7 | module.exports = (Ferdium, settings) => { | 7 | module.exports = (Ferdium, settings) => { |
8 | Ferdium.injectCSS(_path.default.join(__dirname, 'style.css')); | 8 | Ferdium.injectCSS(_path.default.join(__dirname, 'style.css')); |
9 | 9 | ||
10 | // TODO: See how this can be moved into the main ferdium app and sent as an ipc message for opening with a new window or same Ferdium recipe's webview based on user's preferences | 10 | // TODO: See how this can be moved into the main ferdium app and sent as an ipc message for opening with a new window or same Ferdium recipe's webview based on user's preferences |
11 | document.addEventListener('click', event => { | 11 | document.addEventListener( |
12 | const link = event.target.closest('a[href^="http"]'); | 12 | 'click', |
13 | const button = event.target.closest('button[title^="http"]'); | 13 | event => { |
14 | const link = event.target.closest('a[href^="http"]'); | ||
15 | const button = event.target.closest('button[title^="http"]'); | ||
14 | 16 | ||
15 | if (link || button) { | 17 | if (link || button) { |
16 | const url = link ? link.getAttribute('href') : button.getAttribute('title'); | 18 | const url = link |
19 | ? link.getAttribute('href') | ||
20 | : button.getAttribute('title'); | ||
17 | 21 | ||
18 | if (!Ferdium.isImage(link)) { | 22 | if (!Ferdium.isImage(link)) { |
19 | event.preventDefault(); | 23 | event.preventDefault(); |
20 | event.stopPropagation(); | 24 | event.stopPropagation(); |
21 | 25 | ||
22 | if (settings.trapLinkClicks === true) { | 26 | if (settings.trapLinkClicks === true) { |
23 | window.location.href = url; | 27 | window.location.href = url; |
24 | } else { | 28 | } else { |
25 | Ferdium.openNewWindow(url); | 29 | Ferdium.openNewWindow(url); |
30 | } | ||
26 | } | 31 | } |
27 | } | 32 | } |
28 | } | 33 | }, |
29 | }, true); | 34 | true, |
35 | ); | ||
30 | }; | 36 | }; |