REFACTOR Moving singles files to a dedicated folder
This commit is contained in:
parent
2a64076f85
commit
3b0b0d226d
|
|
@ -1,63 +0,0 @@
|
||||||
export default function singles(): void {
|
|
||||||
const isSingleRevue: HTMLElement | null =
|
|
||||||
document.querySelector('.page--single-revue');
|
|
||||||
const isSingleArticle: HTMLElement | null =
|
|
||||||
document.querySelector('.page--single-articles');
|
|
||||||
if (!isSingleRevue && !isSingleArticle) return;
|
|
||||||
|
|
||||||
handleCiteButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
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 ! <br> Vous pouvez maintenant la coller dans votre document.'
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error('Failed to copy text: ', err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user