Compare commits
4 Commits
d7c3d33bd8
...
562be8f9a7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
562be8f9a7 | ||
|
|
56208a06d8 | ||
|
|
642fad11fc | ||
|
|
27b7b013bc |
|
|
@ -3,6 +3,10 @@
|
||||||
@apply px-8;
|
@apply px-8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#cite-reference {
|
||||||
|
@apply hidden;
|
||||||
|
}
|
||||||
|
|
||||||
.tags__title {
|
.tags__title {
|
||||||
@apply text-lg uppercase font-semibold mt-0 my-4 nunito;
|
@apply text-lg uppercase font-semibold mt-0 my-4 nunito;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import alternatePictures from './alternate-pictures';
|
||||||
import { searchBarInit } from './search-bar';
|
import { searchBarInit } from './search-bar';
|
||||||
import singlesInit from './singles/singles';
|
import singlesInit from './singles/singles';
|
||||||
import archivesInit from './archives/archives';
|
import archivesInit from './archives/archives';
|
||||||
|
import handleCiteButton from './singles/cite-button';
|
||||||
|
|
||||||
window.addEventListener('load', function () {
|
window.addEventListener('load', function () {
|
||||||
menuInit();
|
menuInit();
|
||||||
|
|
@ -16,4 +17,5 @@ window.addEventListener('load', function () {
|
||||||
searchBarInit();
|
searchBarInit();
|
||||||
singlesInit();
|
singlesInit();
|
||||||
archivesInit();
|
archivesInit();
|
||||||
|
handleCiteButton();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
52
resources/js/singles/cite-button.ts
Normal file
52
resources/js/singles/cite-button.ts
Normal file
|
|
@ -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 ! <br> Vous pouvez maintenant la coller dans votre document.',
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error('Failed to copy text: ', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -2,11 +2,13 @@
|
||||||
$currentPostType = get_post_type();
|
$currentPostType = get_post_type();
|
||||||
$shareUrls = build_share_urls();
|
$shareUrls = build_share_urls();
|
||||||
$handleCitation = post_type_supports($currentPostType, 'carhop-citations') ?? false;
|
$handleCitation = post_type_supports($currentPostType, 'carhop-citations') ?? false;
|
||||||
|
$citeReference = get_field('cite_reference', get_the_ID());
|
||||||
|
// write_log($handleCitation);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
<div class="socials-buttons">
|
<div class="socials-buttons">
|
||||||
<?php if ($handleCitation) : ?>
|
<?php if ($handleCitation && !empty($citeReference)) : ?>
|
||||||
<button class="socials-buttons__button socials-buttons__button--cite" <?php echo empty($citeReference) ? 'disabled' : ''; ?> title="<?php echo empty($citeReference) ? 'Citation non disponible' : 'Copier la citation'; ?>">
|
<button class="socials-buttons__button socials-buttons__button--cite" <?php echo empty($citeReference) ? 'disabled' : ''; ?> title="<?php echo empty($citeReference) ? 'Citation non disponible' : 'Copier la citation'; ?>">
|
||||||
<img src="<?php echo get_template_directory_uri(); ?>/resources/img/icons/carhop-citer-article.svg" alt="">
|
<img src="<?php echo get_template_directory_uri(); ?>/resources/img/icons/carhop-citer-article.svg" alt="">
|
||||||
Citer
|
Citer
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user