| 1 |
/** |
| 2 |
* Woo Product Short/Full Description widgets behavior. |
| 3 |
* |
| 4 |
* Toggles trimmed/full description visibility. |
| 5 |
*/ |
| 6 |
(function ($) { |
| 7 |
"use strict"; |
| 8 |
|
| 9 |
const INIT_FLAG = "kaWooDescToggleInit"; |
| 10 |
|
| 11 |
const toggleSection = (wrapper) => { |
| 12 |
if (!wrapper || !wrapper.dataset) return; |
| 13 |
if (wrapper.dataset[INIT_FLAG] === "1") return; |
| 14 |
wrapper.dataset[INIT_FLAG] = "1"; |
| 15 |
|
| 16 |
const prefix = wrapper.classList.contains("ka-woo-product-full-description") |
| 17 |
? "ka-woo-product-full-description" |
| 18 |
: "ka-woo-product-short-description"; |
| 19 |
const trimmed = wrapper.querySelector("." + prefix + "__content.is-trimmed"); |
| 20 |
const full = wrapper.querySelector("." + prefix + "__content.is-full"); |
| 21 |
const btn = wrapper.querySelector("." + prefix + "__toggle"); |
| 22 |
if (!trimmed || !full || !btn) return; |
| 23 |
|
| 24 |
let expanded = false; |
| 25 |
const moreLabel = btn.dataset.more || 'Read more'; |
| 26 |
const lessLabel = btn.dataset.less || 'Show less'; |
| 27 |
|
| 28 |
const apply = () => { |
| 29 |
if (expanded) { |
| 30 |
trimmed.setAttribute('hidden', 'hidden'); |
| 31 |
full.removeAttribute('hidden'); |
| 32 |
btn.textContent = lessLabel; |
| 33 |
wrapper.classList.add('is-expanded'); |
| 34 |
} else { |
| 35 |
full.setAttribute('hidden', 'hidden'); |
| 36 |
trimmed.removeAttribute('hidden'); |
| 37 |
btn.textContent = moreLabel; |
| 38 |
wrapper.classList.remove('is-expanded'); |
| 39 |
} |
| 40 |
}; |
| 41 |
|
| 42 |
btn.addEventListener('click', () => { |
| 43 |
expanded = !expanded; |
| 44 |
apply(); |
| 45 |
}); |
| 46 |
|
| 47 |
apply(); |
| 48 |
}; |
| 49 |
|
| 50 |
const init = () => { |
| 51 |
document.querySelectorAll('.ka-woo-product-short-description').forEach(toggleSection); |
| 52 |
document.querySelectorAll('.ka-woo-product-full-description').forEach(toggleSection); |
| 53 |
}; |
| 54 |
|
| 55 |
const initAll = (root) => { |
| 56 |
const ctx = root && root.querySelectorAll ? root : document; |
| 57 |
ctx.querySelectorAll('.ka-woo-product-short-description').forEach(toggleSection); |
| 58 |
ctx.querySelectorAll('.ka-woo-product-full-description').forEach(toggleSection); |
| 59 |
}; |
| 60 |
|
| 61 |
if (document.readyState === "complete" || document.readyState === "interactive") { |
| 62 |
initAll(document); |
| 63 |
} else { |
| 64 |
document.addEventListener("DOMContentLoaded", () => initAll(document)); |
| 65 |
} |
| 66 |
|
| 67 |
$(window).on("elementor/frontend/init", function () { |
| 68 |
elementorFrontend.hooks.addAction( |
| 69 |
"frontend/element_ready/woo_product_short_description.default", |
| 70 |
function ($scope) { |
| 71 |
initAll($scope && $scope[0] ? $scope[0] : document); |
| 72 |
} |
| 73 |
); |
| 74 |
elementorFrontend.hooks.addAction( |
| 75 |
"frontend/element_ready/woo_product_full_description.default", |
| 76 |
function ($scope) { |
| 77 |
initAll($scope && $scope[0] ? $scope[0] : document); |
| 78 |
} |
| 79 |
); |
| 80 |
}); |
| 81 |
})(jQuery); |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|