aboutsummaryrefslogtreecommitdiff
path: root/p
diff options
context:
space:
mode:
authorGravatar maTh <1645099+math-GH@users.noreply.github.com> 2024-09-07 23:24:05 +0200
committerGravatar GitHub <noreply@github.com> 2024-09-07 23:24:05 +0200
commitf7235bcb54e9f24e4de1f83d7428fa3ff970bb05 (patch)
tree10e23a26d0ec5a8758ac2c760251ad82887ef944 /p
parent93c102d7eab69fee76f50fe207f9d3f4022372ca (diff)
Improved: refactor the sharing menu to use a template instead of duplicated HTML code (#6751)
* <script> --> <template> * sharing menu * normal view, global view (reader view does not have a share button) * fix
Diffstat (limited to 'p')
-rw-r--r--p/scripts/main.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/p/scripts/main.js b/p/scripts/main.js
index a907532b3..663bfe74e 100644
--- a/p/scripts/main.js
+++ b/p/scripts/main.js
@@ -1093,6 +1093,36 @@ function init_stream(stream) {
return true;
}
+ el = ev.target.closest('.item.share a.dropdown-toggle');
+ if (el) {
+ const itemId = el.closest('.flux').id;
+ const templateId = 'share_article_template';
+ const id = itemId;
+ const flux_header_el = el.closest('.flux');
+ const title_el = flux_header_el.querySelector('.item.titleAuthorSummaryDate .item-element.title');
+ const websiteName = ' - ' + flux_header_el.querySelector('.flux_header').dataset.websiteName;
+ const articleAuthors = flux_header_el.querySelector('.flux_header').dataset.articleAuthors;
+ let articleAuthorsText = '';
+ if (articleAuthors.trim().length > 0) {
+ articleAuthorsText = ' (' + articleAuthors + ')';
+ }
+ const link = title_el.href;
+ const title = title_el.textContent;
+ const titleText = title;
+ const div = el.parentElement;
+ const dropdownMenu = div.querySelector('.dropdown-menu');
+ const template = document.getElementById(templateId).innerHTML
+ .replace(/--entryId--/g, id)
+ .replace(/--link--/g, link)
+ .replace(/--titleText--/g, titleText)
+ .replace(/--websiteName--/g, websiteName)
+ .replace(/--articleAuthors--/g, articleAuthorsText);
+ if (!dropdownMenu) {
+ div.insertAdjacentHTML('beforeend', template);
+ }
+ return true;
+ }
+
el = ev.target.closest('.item.share > button[data-type="print"]');
if (el) { // Print
const tmp_window = window.open();