diff options
| author | 2022-03-16 23:23:15 +0100 | |
|---|---|---|
| committer | 2022-03-16 23:23:15 +0100 | |
| commit | a89fce27cbc3f3cdfe0cbc10f1ba63a85efa8ebb (patch) | |
| tree | bcc583f0a7698fa505094236b5b42b4264dbf9f9 /p/scripts/main.js | |
| parent | 9748ac48e40947b80808933213b043dc797670b6 (diff) | |
New sharing service: Web sharing API (#4271)
* new optional option: HTMLtag
* Update main.js
* add: web sharing API
* Update gen.php
* Update gen.php
* Update gen.php
* fix spaces
* Update shares.php
* fixed JavaScript
* Update template.rtl.css
* Typo
* improved: if (!navigator.share)
* Update main.js
* comma-dangle only for arrays and objects
* Update app/i18n/fr/gen.php
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
* i18n: System sharing
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'p/scripts/main.js')
| -rw-r--r-- | p/scripts/main.js | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/p/scripts/main.js b/p/scripts/main.js index c9627b606..be1f7c924 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -1018,7 +1018,7 @@ function init_stream(stream) { return true; } - el = ev.target.closest('.item.share > a[data-type="print"]'); + el = ev.target.closest('.item.share > button[data-type="print"]'); if (el) { // Print const tmp_window = window.open(); for (let i = 0; i < document.styleSheets.length; i++) { @@ -1032,9 +1032,19 @@ function init_stream(stream) { return false; } - el = ev.target.closest('.item.share > a[data-type="clipboard"]'); + el = ev.target.closest('.item.share > button[data-type="clipboard"]'); if (el && navigator.clipboard) { // Clipboard - navigator.clipboard.writeText(el.href); + navigator.clipboard.writeText(el.dataset.url); + return false; + } + + el = ev.target.closest('.item.share > button[data-type="web-sharing-api"]'); + if (el && navigator.share) { // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share + const shareData = { + url: el.dataset.url, + title: decodeURI(el.dataset.title), + }; + navigator.share(shareData); return false; } @@ -1068,6 +1078,15 @@ function init_stream(stream) { } }; + if (!navigator.share) { + // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share + // do not show the menu entry if browser does not support navigator.share + document.styleSheets[0].insertRule( + 'button.as-link[data-type="web-sharing-api"] {display: none !important;}', + document.styleSheets[0].cssRules.length + ); + } + stream.onmouseup = function (ev) { // Mouseup enables us to catch middle click, and control+click in IE/Edge if (ev.altKey || ev.metaKey || ev.shiftKey) { return; |
