Files
folio/public/assets/js/share.js
T
cedricAbonnel 3b22be94e8 feat : barre de partage articles + déduplication images uploadées (v1.6.20)
- post_view.php : barre de partage (mail, X, LinkedIn, Mastodon, copier, Web Share) sur articles publiés (#47)
- share.js : logique clipboard + navigator.share sans script tiers, compatible CSP (#47)
- addFile() : hardlink vers fichier identique si même hash16-size.ext dans un autre article (#35)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 10:56:43 +02:00

41 lines
1.4 KiB
JavaScript

(function () {
'use strict';
var bar = document.getElementById('share-bar');
if (!bar) { return; }
var url = bar.getAttribute('data-url') || window.location.href;
var title = bar.getAttribute('data-title') || document.title;
var copyBtn = document.getElementById('share-copy');
if (copyBtn) {
copyBtn.addEventListener('click', function () {
if (!navigator.clipboard) {
var ta = document.createElement('textarea');
ta.value = url;
document.body.appendChild(ta);
ta.select();
document.execCommand('copy');
document.body.removeChild(ta);
copyBtn.textContent = 'Copié !';
setTimeout(function () { copyBtn.textContent = 'Copier le lien'; }, 2000);
return;
}
navigator.clipboard.writeText(url).then(function () {
copyBtn.textContent = 'Copié !';
setTimeout(function () { copyBtn.textContent = 'Copier le lien'; }, 2000);
});
});
}
var nativeBtn = document.getElementById('share-native');
if (nativeBtn) {
if (navigator.share) {
nativeBtn.hidden = false;
nativeBtn.addEventListener('click', function () {
navigator.share({ title: title, url: url }).catch(function () {});
});
}
}
}());