Changeset b5a09ce2 in Klonkt for src/views/shell.ejs


Ignore:
Timestamp:
06/30/2026 05:32:33 PM (2 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
857a06f
Parents:
1d6f9a2
Message:

feat(video-cover): frontend — render animated covers as iOS video, capture in editor

  • post-edit.ejs: hidden cover_video_url field; the cover uploader stores the returned MP4 url
  • post.ejs: the cover <img> carries data-ios-mp4 when a loop MP4 exists
  • shell.ejs: on iOS, swap <img data-ios-mp4> for a muted looping inline <video> (runs on load + htmx swaps); every other browser keeps the crisp WebP

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/views/shell.ejs

    r1d6f9a2 rb5a09ce2  
    771771  document.body.addEventListener('htmx:afterSettle', function (e) { scan(e.target); });
    772772})();
     773
     774// iOS animated-cover → video: an animated WebP is janky on iOS Safari, so on iOS we swap any
     775// <img data-ios-mp4="…"> for a muted, looping, inline <video> (the WebP's matching MP4). Every
     776// other browser keeps the crisp WebP. Runs on load + htmx swaps.
     777(function () {
     778  if (window.__iosVideoWired) return; window.__iosVideoWired = true;
     779  var ua = navigator.userAgent || '';
     780  var IS_IOS = /iP(hone|od|ad)/.test(navigator.platform || '') || /iPad|iPhone|iPod/.test(ua) ||
     781               (/Macintosh/.test(ua) && navigator.maxTouchPoints > 1); // iPadOS reports as Mac
     782  if (!IS_IOS) return;
     783  function swap(root) {
     784    (root || document).querySelectorAll('img[data-ios-mp4]').forEach(function (img) {
     785      var mp4 = img.getAttribute('data-ios-mp4');
     786      if (!mp4 || img.dataset.iosSwapped) return;
     787      img.dataset.iosSwapped = '1';
     788      var v = document.createElement('video');
     789      v.src = mp4; v.muted = true; v.loop = true; v.autoplay = true;
     790      v.setAttribute('muted', ''); v.setAttribute('playsinline', ''); v.setAttribute('webkit-playsinline', '');
     791      v.poster = img.getAttribute('src') || '';
     792      v.className = img.className;
     793      if (img.getAttribute('style')) v.setAttribute('style', img.getAttribute('style'));
     794      if (img.parentNode) img.parentNode.replaceChild(v, img);
     795      var p = v.play && v.play(); if (p && p.catch) p.catch(function () {});
     796    });
     797  }
     798  swap(document);
     799  document.body.addEventListener('htmx:afterSettle', function (e) { swap(e.target); });
     800})();
    773801</script>
    774802
Note: See TracChangeset for help on using the changeset viewer.