Changeset 28f797d in Klonkt for src/views


Ignore:
Timestamp:
06/30/2026 04:31:56 PM (2 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
ecbfa41
Parents:
28bf7f0
Message:

feat(post): share button at the bottom of posts

A "Share/Deel" button under the post (visible to everyone). Uses the Web Share API (native share
sheet) where available, otherwise copies the post URL to the clipboard with a "Link copied"
confirmation. Wired through the existing delegated click handler (CSP-safe, no inline on*).

  • src/views/pages/post.ejs — share button + feedback span
  • src/views/shell.ejs — data-share delegated handler (navigator.share / clipboard)
  • src/services/i18n.js — post.share, post.share_copied (nl/en/de)

Co-Authored-By: Claude <noreply@…>

Location:
src/views
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/views/pages/post.ejs

    r28bf7f0 r28f797d  
    5656    </div>
    5757  <% } %>
     58
     59  <div class="post-share" style="margin:1.25rem 0;display:flex;align-items:center;gap:.6rem;flex-wrap:wrap">
     60    <button type="button" class="btn post-share-btn" data-share data-share-title="<%= post.title %>">🔗 <%= t('post.share') %></button>
     61    <span class="post-share-feedback" id="post-share-feedback" style="color:var(--accent);font-size:.85rem" hidden><%= t('post.share_copied') %></span>
     62  </div>
    5863
    5964  <!-- Inline admin actions: only visible if user has permission -->
  • src/views/shell.ejs

    r28bf7f0 r28f797d  
    807807  // Misc click helpers (select-all in a field, history-back button).
    808808  document.addEventListener('click', function (e) {
    809     var el = e.target.closest && e.target.closest('[data-selectall],[data-back]');
     809    var el = e.target.closest && e.target.closest('[data-selectall],[data-back],[data-share]');
    810810    if (!el) return;
    811811    if (el.dataset.selectall !== undefined && el.select) el.select();
    812812    if (el.dataset.back !== undefined) { e.preventDefault(); history.back(); }
     813    if (el.dataset.share !== undefined) {
     814      e.preventDefault();
     815      var url = location.href, title = el.dataset.shareTitle || document.title;
     816      if (navigator.share) { navigator.share({ title: title, url: url }).catch(function () {}); }
     817      else if (navigator.clipboard && navigator.clipboard.writeText) {
     818        navigator.clipboard.writeText(url).then(function () {
     819          var fb = document.getElementById('post-share-feedback');
     820          if (fb) { fb.hidden = false; setTimeout(function () { fb.hidden = true; }, 2000); }
     821        }).catch(function () { window.prompt('Copy link:', url); });
     822      } else { window.prompt('Copy link:', url); }
     823    }
    813824  });
    814825  // Image fallback (the error event doesn't bubble → capture phase).
Note: See TracChangeset for help on using the changeset viewer.