Bỏ qua nội dung
/* ========== hiệu ứng Tesla đơn giản ========== */
/* ======== hiệu ứng văn bản + Màu ======== */
/* =================================================
NUT XEM THEM TIEU DE SAN PHAM
================================================= */
console.log("JS nut xem them dang chay");
document.addEventListener("DOMContentLoaded", function(){
function initProductTitleToggle(){
var title = document.querySelector(".single-product .product_title");
if(!title) return;
if(title.closest(".product-title-container")) return;
var wrap = document.createElement("div");
wrap.className = "product-title-container";
title.parentNode.insertBefore(wrap, title);
wrap.appendChild(title);
var fade = document.createElement("div");
fade.className = "product-title-fade";
var button = document.createElement("button");
button.type = "button";
button.className = "product-title-toggle";
button.setAttribute("aria-expanded", "false");
button.innerHTML =
'Xem thêm' +
'' +
'' +
'';
wrap.appendChild(fade);
wrap.appendChild(button);
var text = button.querySelector(".product-title-toggle-text");
function isOverflowing(el){
return el.scrollHeight > el.clientHeight + 5;
}
function updateButtonVisibility(){
if(title.classList.contains("is-expanded")){
button.style.display = "inline-flex";
fade.classList.add("is-hidden");
return;
}
if(isOverflowing(title)){
button.style.display = "inline-flex";
fade.classList.remove("is-hidden");
}else{
button.style.display = "none";
fade.style.display = "none";
}
}
updateButtonVisibility();
button.addEventListener("click", function(){
var expanded = title.classList.toggle("is-expanded");
button.classList.toggle("is-expanded", expanded);
button.setAttribute("aria-expanded", expanded ? "true" : "false");
text.textContent = expanded ? "Thu gọn" : "Xem thêm";
if(expanded){
fade.classList.add("is-hidden");
}else{
fade.classList.remove("is-hidden");
}
});
window.addEventListener("resize", function(){
if(!title.classList.contains("is-expanded")){
updateButtonVisibility();
}
});
}
initProductTitleToggle();
});