From 56208a06d83c340d425034994c1442f52b10e6d7 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Tue, 5 May 2026 11:11:15 +0200 Subject: [PATCH] FEATURE Handlign cite button --- resources/js/singles/cite-button.ts | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 resources/js/singles/cite-button.ts diff --git a/resources/js/singles/cite-button.ts b/resources/js/singles/cite-button.ts new file mode 100644 index 0000000..b013a3c --- /dev/null +++ b/resources/js/singles/cite-button.ts @@ -0,0 +1,52 @@ +export default function handleCiteButton(): void { + const citeButton: HTMLElement | null = document.querySelector( + '.socials-buttons__button--cite', + ); + + const citeReference: HTMLElement | null = document.querySelector('#cite-reference'); + if (!citeButton || !citeReference) return; + + if (!window.isSecureContext) { + citeButton.setAttribute('disabled', 'true'); + citeButton.setAttribute( + 'title', + 'Vous devez utiliser un navigation sécurisé (https) pour copier la citation', + ); + } + + citeButton.addEventListener('click', () => { + const textToCopy = citeReference.textContent; + if (!textToCopy) return; + + if (navigator.clipboard && window.isSecureContext) { + navigator.clipboard + .writeText(textToCopy) + .then(() => { + const notyf = new Notyf({ + duration: 4000, + ripple: false, + dismissible: true, + types: [ + { + type: 'success', + icon: { + className: 'notyf__icon--success', + tagName: 'i', + }, + }, + ], + position: { + x: 'right', + y: 'top', + }, + }); + notyf.success( + 'Citation copiée dans le presse-papiers !
Vous pouvez maintenant la coller dans votre document.', + ); + }) + .catch((err) => { + console.error('Failed to copy text: ', err); + }); + } + }); +}