PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.83
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.83
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / widgets / Woo_Archive_Description / script.js

script.js in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.83, at includes/widgets/Woo_Archive_Description/script.js

54 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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