Compare commits

..

No commits in common. "f336917b626a5339a164aa1ed546dafc6065bffe" and "9a3d2da4124849030a620f76e25453b65f9e2c79" have entirely different histories.

2 changed files with 12 additions and 41 deletions

View File

@ -12,7 +12,6 @@ the_header(
?>
<div id="recipe-id" hidden><?= $context['recipe']->get_id() ?></div>
<div id="in-usermenu" hidden><?= $context['recipe']->in_usermenu; ?></div>
<div class="container">
<div class="single-recipe">

View File

@ -15,41 +15,13 @@ document.addEventListener('click', (e) => {
const options = document.querySelectorAll('.dropdown-item');
const inUsermenu = document.getElementById('in-usermenu').textContent;
if (inUsermenu) {
options.forEach(option => {
if (option.getAttribute('data-value') === inUsermenu && option.getAttribute('data-value') !== 'remove') {
option.classList.add('dropdown-selected');
toggleBtn.textContent = option.textContent;
}
});
}
options.forEach(option => {
option.addEventListener('click', async (e) => {
option.addEventListener('click', () => {
const selectedValue = option.getAttribute('data-value');
options.forEach(opt => opt.classList.remove('dropdown-selected'));
const formData = new FormData();
formData.append('action', 'usermenu');
formData.append('recipe_id', recipeId);
formData.append('dayofweek', selectedValue);
const response = await fetch('/ajax', {
method: 'POST',
body: formData
});
const json = await response.json();
if (!response.ok) {
const message = json.error;
showToastify(message, 'error');
return;
}
if (selectedValue === 'remove') {
toggleBtn.textContent = 'Add to list';
} else {
@ -59,7 +31,7 @@ options.forEach(option => {
dropdown.classList.add('hidden');
showToastify(json.success, 'success');
alert(`You selected: ${selectedValue}`);
});
});
@ -70,20 +42,20 @@ const qrPopup = document.querySelector(".qr-popup");
const overlay = document.getElementById('overlay');
qrBtn.addEventListener("click", () => {
qrPopup.classList.toggle("hidden")
overlay.classList.toggle("hidden")
qrContainer.innerHTML = "";
new QRCode(qrContainer, {
text: window.location.href,
width: 200,
height: 200
});
setTimeout(() => {
const qrImg = qrContainer.querySelector("img");
if (qrImg) {
@ -92,8 +64,8 @@ qrBtn.addEventListener("click", () => {
}, 500);
});
document.addEventListener('click', (e) => {
if (!qrPopup.contains(e.target) && !qrBtn.contains(e.target)) {
document.addEventListener('click', (e) =>{
if(!qrPopup.contains(e.target) && !qrBtn.contains(e.target)){
qrPopup.classList.add("hidden");
overlay.classList.add("hidden");
}
@ -113,7 +85,7 @@ favoriteBtn.addEventListener('click', async (e) => {
formData.append('type', type);
favoriteBtn.disabled = true;
const response = await fetch('/ajax', {
const response = await fetch('/ajax', {
method: 'POST',
body: formData
});
@ -121,20 +93,20 @@ favoriteBtn.addEventListener('click', async (e) => {
const json = await response.json();
if (!response.ok) {
if(!response.ok) {
const message = json.error;
showToastify(message, 'error');
return;
}
favoriteBtn.classList.toggle('active');
if (type == 'add') {
if(type == 'add') {
favoriteIcon.classList.remove('fa-regular');
favoriteIcon.classList.add('fa-solid');
} else {
favoriteIcon.classList.add('fa-regular');
favoriteIcon.classList.remove('fa-solid');
}
showToastify(json.success, 'success');
});