10 Jul 2025
prueba 2 cachorro hembra blanco
document.addEventListener("DOMContentLoaded", function () {
/* ========================================================
* Codi Original de Filtres i Data Atributs (Manté)
* ======================================================== */
// === Codi original per completar ALT i data-* ===
document.querySelectorAll(".poc-puppy-card").forEach(function(card) {
const nameEl = card.querySelector(".poc-puppy-name");
const thumbEl = card.querySelector(".poc-puppy-thumb img");
if (nameEl && thumbEl) {
const name = nameEl.textContent.trim();
const slug = name
.toLowerCase()
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "")
.replace(/\s+/g, "-");
thumbEl.alt = name;
thumbEl.setAttribute("data-name", name);
thumbEl.setAttribute("data-slug", slug);
}
});
// === Codi original per a Filtres per color / sex / premios ===
document.querySelectorAll(".poc-puppies-filters").forEach(function(filtersWrapper) {
let grid = null;
let sib = filtersWrapper.nextElementSibling;
while (sib) {
if (sib.classList && sib.classList.contains("poc-puppies-grid")) {
grid = sib;
break;
}
sib = sib.nextElementSibling;
}
if (!grid) return;
const buttons = filtersWrapper.querySelectorAll("[data-filter]");
const cards = grid.querySelectorAll(".poc-puppy-card");
if (!buttons.length || !cards.length) return;
buttons.forEach(function(btn) {
btn.addEventListener("click", function(e) {
e.preventDefault();
buttons.forEach(function(b) {
b.classList.remove("active", "is-active");
});
btn.classList.add("active");
const filter = btn.getAttribute("data-filter") || "*";
cards.forEach(function(card) {
const colors = (card.getAttribute("data-color") || "").split(" ").filter(Boolean);
const sexes = (card.getAttribute("data-sex") || "").split(" ").filter(Boolean);
const premios = (card.getAttribute("data-premios") || "").split(" ").filter(Boolean);
let show = true;
if (filter === "*" || filter === "all") {
show = true;
} else if (filter.indexOf("color:") === 0) {
const val = filter.replace("color:", "");
show = colors.includes(val);
} else if (filter.indexOf("sex:") === 0) {
const val = filter.replace("sex:", "");
show = sexes.includes(val);
} else if (filter.indexOf("premios:") === 0) {
const val = filter.replace("premios:", "");
if (val === "otros") {
const hasKnown =
premios.includes("nacionales") ||
premios.includes("internacionales");
show = !hasKnown;
} else {
show = premios.includes(val);
}
}
card.style.display = show ? "" : "none";
});
});
});
});
// ========================================================
// === FIX FINAL: REACTIVACIÓ DE LA GALERIA LIGHTBOX (PrettyPhoto) ===
// S'executa després de la càrrega per engegar el plugin manualment a la nostra imatge custom.
// ========================================================
// Funció que inicialitza PrettyPhoto al nostre enllaç custom
var initCustomLightbox = function() {
if (typeof jQuery !== 'undefined' && typeof jQuery.fn.prettyPhoto !== 'undefined') {
// Re-inicialitza PrettyPhoto al nostre enllaç custom
jQuery('.poc-custom-image-wrapper a').prettyPhoto({
social_tools: false,
theme: 'pp_default',
deeplinking: false,
allow_resize: true,
// Molt important: Forçar la recàrrega de la galeria de PrettyPhoto
hook: 'data-rel',
animationSpeed: 'normal',
opacity: 0.80,
show_title: false,
horizontal_padding: 20,
});
// Si hi ha altres galeries (thumbnails), també les inicialitza
jQuery('a[data-rel^="prettyPhoto"]').prettyPhoto({
hook: 'data-rel',
theme: 'pp_default'
});
}
};
// Utilitzem un retard de seguretat (1 segon) per assegurar que el tema Luxa ha carregat la llibreria de PrettyPhoto.
setTimeout(initCustomLightbox, 1000);
});
document.addEventListener("DOMContentLoaded", function () {
/* [El teu codi original de Filtres (omès per brevetat)] */
// ... Codi de Filtres de Cachorros i data-attributes ...
// === FIX FINAL: REACTIVACIÓ DE LA GALERIA LIGHTBOX (PrettyPhoto) ===
var initCustomLightbox = function() {
if (typeof jQuery !== 'undefined' && typeof jQuery.fn.prettyPhoto !== 'undefined') {
// Re-inicialitza PrettyPhoto al nostre enllaç custom
jQuery('.poc-custom-image-wrapper a').prettyPhoto({
social_tools: false,
theme: 'pp_default',
deeplinking: false,
allow_resize: true,
// Aquesta línia és crucial per la funcionalitat de la galeria de múltiples imatges.
hook: 'data-rel',
animationSpeed: 'normal',
opacity: 0.80,
show_title: false,
horizontal_padding: 20,
});
// Si hi ha altres galeries (seguretat)
jQuery('a[data-rel^="prettyPhoto"]').prettyPhoto({
hook: 'data-rel',
theme: 'pp_default'
});
}
};
// Utilitzem un retard de seguretat més llarg (1.5 segons) per assegurar que el tema Luxa ha carregat PrettyPhoto i jQuery.
// L'error anterior es devia al fet que jQuery encara no estava preparat.
setTimeout(initCustomLightbox, 1500);
});