| 1 |
/** |
| 2 |
* Woo Archive Description widget behaviour. |
| 3 |
* |
| 4 |
* Expands a trimmed description when the "Read more" control is used. The |
| 5 |
* markup ships both the trimmed and the full text; this only swaps which one |
| 6 |
* is visible. |
| 7 |
*/ |
| 8 |
(function () { |
| 9 |
'use strict'; |
| 10 |
|
| 11 |
const BOUND = 'kaArchiveDescriptionBound'; |
| 12 |
|
| 13 |
const bind = (wrap) => { |
| 14 |
if (!wrap || !wrap.dataset || wrap.dataset[BOUND] === '1') { |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
const button = wrap.querySelector('.ka-woo-archive-description__readmore'); |
| 19 |
const short = wrap.querySelector('.ka-woo-archive-description__short'); |
| 20 |
const full = wrap.querySelector('.ka-woo-archive-description__full'); |
| 21 |
if (!button || !short || !full) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
wrap.dataset[BOUND] = '1'; |
| 26 |
const moreLabel = button.textContent; |
| 27 |
const lessLabel = button.dataset.lessText || ''; |
| 28 |
|
| 29 |
button.addEventListener('click', () => { |
| 30 |
const expanded = button.getAttribute('aria-expanded') === 'true'; |
| 31 |
short.hidden = !expanded; |
| 32 |
full.hidden = expanded; |
| 33 |
button.setAttribute('aria-expanded', expanded ? 'false' : 'true'); |
| 34 |
if (lessLabel) { |
| 35 |
button.textContent = expanded ? moreLabel : lessLabel; |
| 36 |
} |
| 37 |
}); |
| 38 |
}; |
| 39 |
|
| 40 |
const init = (scope) => { |
| 41 |
const root = scope && scope.querySelectorAll ? scope : document; |
| 42 |
root.querySelectorAll('[data-ka-expandable="1"]').forEach(bind); |
| 43 |
}; |
| 44 |
|
| 45 |
document.addEventListener('DOMContentLoaded', () => init(document)); |
| 46 |
|
| 47 |
if (window.elementorFrontend && window.elementorFrontend.hooks) { |
| 48 |
window.elementorFrontend.hooks.addAction( |
| 49 |
'frontend/element_ready/woo_archive_description.default', |
| 50 |
(scope) => init(scope && scope[0] ? scope[0] : document) |
| 51 |
); |
| 52 |
} |
| 53 |
})(); |
| 54 |
|