mirror of https://github.com/miniflux/v2.git
Use Web Share API for sharing entry
This commit is contained in:
parent
bf4823bdbd
commit
061f12fbb0
|
@ -49,6 +49,7 @@
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ route "sharedEntry" "shareCode" .entry.ShareCode }}"
|
<a href="{{ route "sharedEntry" "shareCode" .entry.ShareCode }}"
|
||||||
title="{{ t "entry.shared_entry.title" }}"
|
title="{{ t "entry.shared_entry.title" }}"
|
||||||
|
data-share-status="shared"
|
||||||
target="_blank">{{ icon "share" }}<span class="icon-label">{{ t "entry.shared_entry.label" }}</span></a>
|
target="_blank">{{ icon "share" }}<span class="icon-label">{{ t "entry.shared_entry.label" }}</span></a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -64,6 +65,7 @@
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ route "shareEntry" "entryID" .entry.ID }}"
|
<a href="{{ route "shareEntry" "entryID" .entry.ID }}"
|
||||||
title="{{ t "entry.share.title" }}"
|
title="{{ t "entry.share.title" }}"
|
||||||
|
data-share-status="share"
|
||||||
target="_blank">{{ icon "share" }}<span class="icon-label">{{ t "entry.share.label" }}</span></a>
|
target="_blank">{{ icon "share" }}<span class="icon-label">{{ t "entry.share.label" }}</span></a>
|
||||||
</li>
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -638,3 +638,43 @@ function handlePlayerProgressionSave(playerElement) {
|
||||||
request.execute();
|
request.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handle new share entires and already shared entries
|
||||||
|
*/
|
||||||
|
function handleShare() {
|
||||||
|
let link = document.querySelector('a[data-share-status]');
|
||||||
|
let title = document.querySelector("body > main > section > header > h1 > a");
|
||||||
|
if (link.dataset.shareStatus === "shared") {
|
||||||
|
checkShareAPI(title, link.href);
|
||||||
|
}
|
||||||
|
if (link.dataset.shareStatus === "share") {
|
||||||
|
let request = new RequestBuilder(link.href);
|
||||||
|
request.withCallback((r) => {
|
||||||
|
checkShareAPI(title, r.url);
|
||||||
|
});
|
||||||
|
request.withHttpMethod("GET");
|
||||||
|
request.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wrapper for Web Share API
|
||||||
|
*/
|
||||||
|
function checkShareAPI(title, url) {
|
||||||
|
if (!navigator.canShare) {
|
||||||
|
console.error("Your browser doesn't support the Web Share API.");
|
||||||
|
window.location = url;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
navigator.share({
|
||||||
|
title: title,
|
||||||
|
url: url
|
||||||
|
});
|
||||||
|
window.location.reload();
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,6 +52,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||||
onClick("a[data-toggle-bookmark]", (event) => handleBookmark(event.target));
|
onClick("a[data-toggle-bookmark]", (event) => handleBookmark(event.target));
|
||||||
onClick("a[data-fetch-content-entry]", () => handleFetchOriginalContent());
|
onClick("a[data-fetch-content-entry]", () => handleFetchOriginalContent());
|
||||||
onClick("a[data-action=search]", (event) => setFocusToSearchInput(event));
|
onClick("a[data-action=search]", (event) => setFocusToSearchInput(event));
|
||||||
|
onClick("a[data-share-status]", () => handleShare());
|
||||||
onClick("a[data-action=markPageAsRead]", (event) => handleConfirmationMessage(event.target, () => markPageAsRead()));
|
onClick("a[data-action=markPageAsRead]", (event) => handleConfirmationMessage(event.target, () => markPageAsRead()));
|
||||||
onClick("a[data-toggle-status]", (event) => handleEntryStatus("next", event.target));
|
onClick("a[data-toggle-status]", (event) => handleEntryStatus("next", event.target));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue