From a7cc6468818ccc8101f6b24850d4a14b8dc9d55f Mon Sep 17 00:00:00 2001 From: Ricardo Date: Sat, 28 Feb 2026 08:20:55 +0100 Subject: [PATCH] feat: add share-post.js module for Post buttons --- js/share-post.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 js/share-post.js diff --git a/js/share-post.js b/js/share-post.js new file mode 100644 index 0000000..9b9a453 --- /dev/null +++ b/js/share-post.js @@ -0,0 +1,38 @@ +/** + * Share Post — frontend module + * Opens the Indiekit share form in a popup window for creating posts + * from blogroll, podroll, and news page items. + * Only active when user is logged in (body[data-indiekit-auth="true"]). + */ +(function () { + function isLoggedIn() { + return document.body.getAttribute('data-indiekit-auth') === 'true'; + } + + function openSharePopup(button) { + var url = button.dataset.shareUrl; + var title = button.dataset.shareTitle || ''; + var type = button.dataset.shareType || 'note'; + if (!url) return; + + var shareUrl = '/share/bookmarklet' + + '?name=' + encodeURIComponent(title) + + '&url=' + encodeURIComponent(url) + + '&type=' + encodeURIComponent(type); + + window.open( + shareUrl, + 'Sharer', + 'resizable,scrollbars,status=0,toolbar=0,menubar=0,titlebar=0,width=578,height=720,location=0' + ); + } + + document.addEventListener('click', function (e) { + if (!isLoggedIn()) return; + var button = e.target.closest('.share-post-btn'); + if (button) { + e.preventDefault(); + openSharePopup(button); + } + }); +})();