|
Characteristic
|
${data1.name}
|
${data2.name}
|
| Size |
${data1.size} |
${data2.size} |
| Weight |
${data1.weight} |
${data2.weight} |
| Height |
${data1.height} |
${data2.height} |
| Lifespan |
${data1.lifespan} |
${data2.lifespan} |
| Temperament |
${data1.temperament} |
${data2.temperament} |
| Energy Level |
${data1.energy} |
${data2.energy} |
| Grooming |
${data1.grooming} |
${data2.grooming} |
| Shedding |
${data1.shedding} |
${data2.shedding} |
| Trainability |
${data1.trainability} |
${data2.trainability} |
| Good With Children |
${data1.children} |
${data2.children} |
| Good With Other Pets |
${data1.pets} |
${data2.pets} |
| Apartment Suitability |
${data1.apartment} |
${data2.apartment} |
View Full ${data1.name} vs ${data2.name} Comparison →
`;
setTimeout(
function () {
result.scrollIntoView({
behavior: "smooth",
block: "start"
});
},
100
);
}
);
/* ==========================================
INITIAL LOAD
========================================== */
loadSpecies("dog");
})();
${breed.name}
${breed.description}
View Breed →
`;
}
);
results.innerHTML = `
${cards}
`;
results.classList.add(
"active"
);
document
.getElementById(
"pbg-restart"
)
.addEventListener(
"click",
restartQuiz
);
results.scrollIntoView({
behavior: "smooth",
block: "start"
});
}
/* =================================================
RESTART
================================================= */
function restartQuiz() {
currentStep = 1;
answers.species = "";
answers.home = "";
answers.activity = "";
answers.grooming = "";
answers.priority = "";
document
.querySelectorAll(
".pbg-option"
)
.forEach(
function (option) {
option.classList.remove(
"selected"
);
}
);
quiz.style.display =
"";
document
.querySelector(
".pbg-finder-navigation"
)
.style.display =
"";
document
.querySelector(
".pbg-finder-progress"
)
.style.display =
"";
results.classList.remove(
"active"
);
results.innerHTML =
"";
showStep(1);
}
/* =================================================
INITIALIZE
================================================= */
showStep(1);
})();
`
: `
`;
card.innerHTML = `
${imageHTML}
${breed.title}
Read Guide →
`;
return card;
}
/* =========================================
LOAD BREEDS
========================================= */
async function loadBreeds() {
const breedLinks =
await getBreedLinks();
if (!breedLinks.length) {
carousel.innerHTML =
`
No dog breed pages found.
`;
return;
}
/*
* Create cards immediately.
* This means the carousel doesn't have
* to wait for every image.
*/
carousel.innerHTML = "";
breedLinks.forEach(function (breed) {
const card =
createCard(
breed,
null
);
carousel.appendChild(card);
/*
* Load image independently
*/
getBreedImage(
breed.url
).then(function (image) {
if (!image) return;
const img =
card.querySelector("img");
if (img) {
img.src = image;
} else {
const imageContainer =
card.querySelector(
".pbg-dog-image"
);
if (imageContainer) {
imageContainer.innerHTML =
`

`;
}
}
});
});
breeds =
breedLinks;
updateCarousel();
startAutoScroll();
}
/* =========================================
VISIBLE CARDS
========================================= */
function getVisibleCards() {
if (
window.innerWidth <= 767
) {
return 1;
}
if (
window.innerWidth <= 1024
) {
return 3;
}
return 4;
}
/* =========================================
UPDATE CAROUSEL
========================================= */
function updateCarousel() {
const card =
carousel.querySelector(
".pbg-dog-card"
);
if (!card) return;
const visible =
getVisibleCards();
const maxIndex =
Math.max(
0,
breeds.length - visible
);
if (
currentIndex > maxIndex
) {
currentIndex = 0;
}
const cardWidth =
card.getBoundingClientRect().width;
const gap = 20;
const offset =
currentIndex *
(cardWidth + gap);
carousel.style.transform =
"translateX(-" +
offset +
"px)";
}
/* =========================================
NEXT
========================================= */
function nextSlide() {
if (!breeds.length) return;
const visible =
getVisibleCards();
const maxIndex =
Math.max(
0,
breeds.length - visible
);
if (
currentIndex >= maxIndex
) {
currentIndex = 0;
} else {
currentIndex++;
}
updateCarousel();
}
/* =========================================
PREVIOUS
========================================= */
function previousSlide() {
if (!breeds.length) return;
const visible =
getVisibleCards();
const maxIndex =
Math.max(
0,
breeds.length - visible
);
if (
currentIndex <= 0
) {
currentIndex = maxIndex;
} else {
currentIndex--;
}
updateCarousel();
}
/* =========================================
AUTO SCROLL
========================================= */
function startAutoScroll() {
clearInterval(
autoScroll
);
autoScroll =
setInterval(
function () {
if (!isHovering) {
nextSlide();
}
},
3500
);
}
/* =========================================
EVENTS
========================================= */
nextButton.addEventListener(
"click",
function () {
nextSlide();
startAutoScroll();
}
);
prevButton.addEventListener(
"click",
function () {
previousSlide();
startAutoScroll();
}
);
carousel.addEventListener(
"mouseenter",
function () {
isHovering = true;
}
);
carousel.addEventListener(
"mouseleave",
function () {
isHovering = false;
}
);
window.addEventListener(
"resize",
function () {
updateCarousel();
}
);
/* =========================================
START
========================================= */
loadBreeds();
})();
`
: `
`;
card.innerHTML = `
${imageHTML}
${breed.title}
Read Guide →
`;
return card;
}
/* =========================================
LOAD CAT BREEDS
========================================= */
async function loadBreeds() {
const breedLinks =
await getBreedLinks();
if (!breedLinks.length) {
carousel.innerHTML = `
No cat breed pages found.
`;
return;
}
/*
* Clear loading message
*/
carousel.innerHTML = "";
/*
* Create all cards
*/
breedLinks.forEach(
function (breed) {
const card =
createCard(
breed,
null
);
carousel.appendChild(
card
);
/*
* Load the breed image
* independently.
*/
getBreedImage(
breed.url
).then(
function (image) {
if (!image) {
return;
}
const img =
card.querySelector(
"img"
);
if (img) {
img.src =
image;
} else {
const imageContainer =
card.querySelector(
".pbg-cat-image"
);
if (
imageContainer
) {
imageContainer.innerHTML = `

`;
}
}
}
);
}
);
breeds =
breedLinks;
updateCarousel();
startAutoScroll();
}
/* =========================================
NUMBER OF VISIBLE CARDS
========================================= */
function getVisibleCards() {
if (
window.innerWidth <= 767
) {
return 1;
}
if (
window.innerWidth <= 1024
) {
return 3;
}
return 4;
}
/* =========================================
UPDATE CAROUSEL POSITION
========================================= */
function updateCarousel() {
const card =
carousel.querySelector(
".pbg-cat-card"
);
if (!card) {
return;
}
const visible =
getVisibleCards();
const maxIndex =
Math.max(
0,
breeds.length - visible
);
if (
currentIndex > maxIndex
) {
currentIndex = 0;
}
const cardWidth =
card.getBoundingClientRect()
.width;
const gap = 20;
const offset =
currentIndex *
(cardWidth + gap);
carousel.style.transform =
"translateX(-" +
offset +
"px)";
}
/* =========================================
NEXT SLIDE
========================================= */
function nextSlide() {
if (!breeds.length) {
return;
}
const visible =
getVisibleCards();
const maxIndex =
Math.max(
0,
breeds.length - visible
);
if (
currentIndex >= maxIndex
) {
currentIndex = 0;
} else {
currentIndex++;
}
updateCarousel();
}
/* =========================================
PREVIOUS SLIDE
========================================= */
function previousSlide() {
if (!breeds.length) {
return;
}
const visible =
getVisibleCards();
const maxIndex =
Math.max(
0,
breeds.length - visible
);
if (
currentIndex <= 0
) {
currentIndex = maxIndex;
} else {
currentIndex--;
}
updateCarousel();
}
/* =========================================
AUTO SCROLL
========================================= */
function startAutoScroll() {
clearInterval(
autoScroll
);
autoScroll =
setInterval(
function () {
if (!isHovering) {
nextSlide();
}
},
3500
);
}
/* =========================================
BUTTON EVENTS
========================================= */
nextButton.addEventListener(
"click",
function () {
nextSlide();
startAutoScroll();
}
);
prevButton.addEventListener(
"click",
function () {
previousSlide();
startAutoScroll();
}
);
/* =========================================
PAUSE ON HOVER
========================================= */
carousel.addEventListener(
"mouseenter",
function () {
isHovering = true;
}
);
carousel.addEventListener(
"mouseleave",
function () {
isHovering = false;
}
);
/* =========================================
RESPONSIVE RESIZE
========================================= */
window.addEventListener(
"resize",
function () {
updateCarousel();
}
);
/* =========================================
START
========================================= */
loadBreeds();
})();
`
: `
`;
card.innerHTML = `
${imageHTML}
${article.title}
Read Article →
`;
return card;
}
/* =========================================
LOAD ARTICLES
========================================= */
async function loadArticles() {
const articleLinks =
await getBlogLinks();
if (!articleLinks.length) {
carousel.innerHTML = `
No dog articles found.
`;
return;
}
carousel.innerHTML = "";
articleLinks.forEach(
function (article) {
const card =
createCard(
article,
null
);
carousel.appendChild(card);
getArticleImage(
article.url
).then(
function (image) {
if (!image) {
return;
}
const img =
card.querySelector(
"img"
);
if (img) {
img.src = image;
} else {
const container =
card.querySelector(
".pbg-blog-image"
);
if (container) {
container.innerHTML = `

`;
}
}
}
);
}
);
articles =
articleLinks;
updateCarousel();
startAutoScroll();
}
/* =========================================
VISIBLE CARDS
========================================= */
function getVisibleCards() {
if (
window.innerWidth <= 767
) {
return 1;
}
if (
window.innerWidth <= 1024
) {
return 2;
}
return 3;
}
/* =========================================
POSITION
========================================= */
function updateCarousel() {
const card =
carousel.querySelector(
".pbg-blog-card"
);
if (!card) {
return;
}
const visible =
getVisibleCards();
const maxIndex =
Math.max(
0,
articles.length - visible
);
if (
currentIndex > maxIndex
) {
currentIndex = 0;
}
const cardWidth =
card.getBoundingClientRect()
.width;
const gap = 20;
const offset =
currentIndex *
(cardWidth + gap);
carousel.style.transform =
"translateX(-" +
offset +
"px)";
}
/* =========================================
NEXT
========================================= */
function nextSlide() {
if (!articles.length) {
return;
}
const visible =
getVisibleCards();
const maxIndex =
Math.max(
0,
articles.length - visible
);
if (
currentIndex >= maxIndex
) {
currentIndex = 0;
} else {
currentIndex++;
}
updateCarousel();
}
/* =========================================
PREVIOUS
========================================= */
function previousSlide() {
if (!articles.length) {
return;
}
const visible =
getVisibleCards();
const maxIndex =
Math.max(
0,
articles.length - visible
);
if (
currentIndex <= 0
) {
currentIndex = maxIndex;
} else {
currentIndex--;
}
updateCarousel();
}
/* =========================================
AUTO SCROLL
========================================= */
function startAutoScroll() {
clearInterval(autoScroll);
autoScroll =
setInterval(
function () {
if (!isHovering) {
nextSlide();
}
},
4000
);
}
/* =========================================
EVENTS
========================================= */
nextButton.addEventListener(
"click",
function () {
nextSlide();
startAutoScroll();
}
);
prevButton.addEventListener(
"click",
function () {
previousSlide();
startAutoScroll();
}
);
carousel.addEventListener(
"mouseenter",
function () {
isHovering = true;
}
);
carousel.addEventListener(
"mouseleave",
function () {
isHovering = false;
}
);
window.addEventListener(
"resize",
function () {
updateCarousel();
}
);
/* =========================================
START
========================================= */
loadArticles();
})();
`
: `
`;
card.innerHTML = `
${imageHTML}
${article.title}
Read Article →
`;
return card;
}
/* =========================================
LOAD ARTICLES
========================================= */
async function loadArticles() {
const articleLinks =
await getBlogLinks();
if (!articleLinks.length) {
carousel.innerHTML = `
No cat articles found.
`;
return;
}
carousel.innerHTML = "";
/* =====================================
CREATE CARDS
===================================== */
articleLinks.forEach(
function (article) {
const card =
createCard(
article,
null
);
carousel.appendChild(
card
);
/* =================================
LOAD ARTICLE IMAGE
================================= */
getArticleImage(
article.url
).then(
function (image) {
if (!image) {
return;
}
const img =
card.querySelector(
"img"
);
if (img) {
img.src =
image;
} else {
const container =
card.querySelector(
".pbg-cat-blog-image"
);
if (container) {
container.innerHTML = `

`;
}
}
}
);
}
);
articles =
articleLinks;
updateCarousel();
startAutoScroll();
}
/* =========================================
VISIBLE CARDS
========================================= */
function getVisibleCards() {
if (
window.innerWidth <= 767
) {
return 1;
}
if (
window.innerWidth <= 1024
) {
return 2;
}
return 3;
}
/* =========================================
UPDATE CAROUSEL
========================================= */
function updateCarousel() {
const card =
carousel.querySelector(
".pbg-cat-blog-card"
);
if (!card) {
return;
}
const visible =
getVisibleCards();
const maxIndex =
Math.max(
0,
articles.length - visible
);
if (
currentIndex > maxIndex
) {
currentIndex = 0;
}
const cardWidth =
card.getBoundingClientRect()
.width;
const gap = 20;
const offset =
currentIndex *
(cardWidth + gap);
carousel.style.transform =
"translateX(-" +
offset +
"px)";
}
/* =========================================
NEXT SLIDE
========================================= */
function nextSlide() {
if (!articles.length) {
return;
}
const visible =
getVisibleCards();
const maxIndex =
Math.max(
0,
articles.length - visible
);
if (
currentIndex >= maxIndex
) {
currentIndex = 0;
} else {
currentIndex++;
}
updateCarousel();
}
/* =========================================
PREVIOUS SLIDE
========================================= */
function previousSlide() {
if (!articles.length) {
return;
}
const visible =
getVisibleCards();
const maxIndex =
Math.max(
0,
articles.length - visible
);
if (
currentIndex <= 0
) {
currentIndex = maxIndex;
} else {
currentIndex--;
}
updateCarousel();
}
/* =========================================
AUTO SCROLL
========================================= */
function startAutoScroll() {
clearInterval(
autoScroll
);
autoScroll =
setInterval(
function () {
if (!isHovering) {
nextSlide();
}
},
4000
);
}
/* =========================================
BUTTON EVENTS
========================================= */
nextButton.addEventListener(
"click",
function () {
nextSlide();
startAutoScroll();
}
);
prevButton.addEventListener(
"click",
function () {
previousSlide();
startAutoScroll();
}
);
/* =========================================
PAUSE ON HOVER
========================================= */
carousel.addEventListener(
"mouseenter",
function () {
isHovering = true;
}
);
carousel.addEventListener(
"mouseleave",
function () {
isHovering = false;
}
);
/* =========================================
RESPONSIVE
========================================= */
window.addEventListener(
"resize",
function () {
updateCarousel();
}
);
/* =========================================
START
========================================= */
loadArticles();
})();
```