From a89fce27cbc3f3cdfe0cbc10f1ba63a85efa8ebb Mon Sep 17 00:00:00 2001 From: maTh Date: Wed, 16 Mar 2022 23:23:15 +0100 Subject: 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 * i18n: System sharing Co-authored-by: Alexandre Alapetite --- p/scripts/main.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'p/scripts/main.js') 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; -- cgit v1.2.3