Compare commits
3 Commits
cc0125d997
...
80a23a5080
| Author | SHA1 | Date | |
|---|---|---|---|
| 80a23a5080 | |||
| f0ed2f0712 | |||
| 6f306beb4b |
@ -11,6 +11,8 @@ the_header(
|
|||||||
);
|
);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<div id="recipe-id" hidden><?= $context['recipe']->get_id() ?></div>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="single-recipe">
|
<div class="single-recipe">
|
||||||
<div class="single-recipe-info">
|
<div class="single-recipe-info">
|
||||||
@ -72,8 +74,8 @@ the_header(
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-btns">
|
<div class="small-btns">
|
||||||
<button class="btn btn-secondary btn-small hover-anim" title="Add To Favorites">
|
<button id="favorite-btn" class="btn btn-secondary btn-small hover-anim <?= $context['recipe']->is_in_favorite ? 'active' : '' ?>" title="Add To Favorites">
|
||||||
<i class="fa-regular fa-heart"></i>
|
<i class="<?= $context['recipe']->is_in_favorite ? 'fa-solid' : 'fa-regular' ?> fa-heart"></i>
|
||||||
</button>
|
</button>
|
||||||
<a class="btn btn-secondary btn-small hover-anim"
|
<a class="btn btn-secondary btn-small hover-anim"
|
||||||
href="<?php the_permalink('recipes:export-pdf', [$context['recipe']->get_id()]); ?>"
|
href="<?php the_permalink('recipes:export-pdf', [$context['recipe']->get_id()]); ?>"
|
||||||
|
|||||||
@ -92,6 +92,15 @@ body {
|
|||||||
.logo {
|
.logo {
|
||||||
max-width: 70px;
|
max-width: 70px;
|
||||||
}
|
}
|
||||||
|
.toastify.info {
|
||||||
|
background: #003a92;
|
||||||
|
}
|
||||||
|
.toastify.error {
|
||||||
|
background: #770000;
|
||||||
|
}
|
||||||
|
.toastify.success {
|
||||||
|
background: #00660f;
|
||||||
|
}
|
||||||
|
|
||||||
/*placeholder for search and login section*/
|
/*placeholder for search and login section*/
|
||||||
.search-and-login {
|
.search-and-login {
|
||||||
@ -638,6 +647,9 @@ hr {
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
.btn:disabled {
|
||||||
|
opacity: 0.3;
|
||||||
|
}
|
||||||
|
|
||||||
.btn-primary {
|
.btn-primary {
|
||||||
background-color: var(--button-primary);
|
background-color: var(--button-primary);
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
const recipeId = document.getElementById('recipe-id').textContent;
|
||||||
const toggleBtn = document.getElementById('day-select');
|
const toggleBtn = document.getElementById('day-select');
|
||||||
const dropdown = document.getElementById('custom-select-dropdown');
|
const dropdown = document.getElementById('custom-select-dropdown');
|
||||||
|
|
||||||
@ -68,4 +69,44 @@ document.addEventListener('click', (e) =>{
|
|||||||
qrPopup.classList.add("hidden");
|
qrPopup.classList.add("hidden");
|
||||||
overlay.classList.add("hidden");
|
overlay.classList.add("hidden");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const favoriteBtn = document.getElementById('favorite-btn');
|
||||||
|
const favoriteIcon = favoriteBtn.querySelector('i');
|
||||||
|
|
||||||
|
|
||||||
|
favoriteBtn.addEventListener('click', async (e) => {
|
||||||
|
const isFavorite = favoriteBtn.classList.contains('active');
|
||||||
|
const type = isFavorite ? 'remove' : 'add';
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('action', 'favorites');
|
||||||
|
formData.append('recipe_id', recipeId);
|
||||||
|
formData.append('type', type);
|
||||||
|
|
||||||
|
favoriteBtn.disabled = true;
|
||||||
|
const response = await fetch('/ajax', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
});
|
||||||
|
favoriteBtn.disabled = false;
|
||||||
|
|
||||||
|
const json = await response.json();
|
||||||
|
|
||||||
|
if(!response.ok) {
|
||||||
|
const message = json.error;
|
||||||
|
showToastify(message, 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
favoriteBtn.classList.toggle('active');
|
||||||
|
|
||||||
|
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');
|
||||||
});
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user