59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
export default function singleRevue() {
|
|
const isSingleRevue = document.querySelector(
|
|
'.page--single-revue'
|
|
);
|
|
if (!isSingleRevue) return;
|
|
|
|
handleButtons();
|
|
hydrateRevueAuthors();
|
|
handleAuthorsButton();
|
|
}
|
|
function getRevueID() {
|
|
const revueID = document
|
|
.querySelector('.page--single-revue')
|
|
.getAttribute('data-revue-id');
|
|
return revueID ?? null;
|
|
}
|
|
|
|
function handleAuthorsButton() {
|
|
const authorsButton = document.querySelector(
|
|
'.authors-button'
|
|
);
|
|
authorsButton.addEventListener('click', () => {
|
|
hydrateRevueAuthors();
|
|
});
|
|
}
|
|
function handleButtons() {
|
|
const socialsButtons = document.querySelectorAll(
|
|
'.socials-buttons__button'
|
|
);
|
|
|
|
const shareButton = document.querySelector(
|
|
'.socials-buttons__button--share'
|
|
);
|
|
shareButton.addEventListener('click', () => {
|
|
// const url = window.location.href;
|
|
// const title = document.title;
|
|
// const text = 'Check out this article: ' + url;
|
|
// const shareUrl =
|
|
// 'https://www.facebook.com/sharer/sharer.php?u=' +
|
|
// encodeURIComponent(url);
|
|
// window.open(shareUrl, '_blank');
|
|
});
|
|
}
|
|
|
|
async function hydrateRevueAuthors() {
|
|
const revueID = getRevueID();
|
|
if (!revueID) return;
|
|
|
|
const response = await fetch(
|
|
`/wp-json/dynamiques-datas/v1/build/revue/authors?revue-id=${revueID}`
|
|
);
|
|
const revueAuthors = await response.json();
|
|
// console.log(revueAuthors);
|
|
|
|
const authorsList =
|
|
document.querySelector('.authors-list');
|
|
authorsList.innerHTML = revueAuthors.html_template;
|
|
}
|