PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.83
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.83
51.1.84 51.1.85 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 All 39 releases
← All changes | includes/widgets/Woo_Archive_Description/script.js +42 -23 51.1.6451.1.83 View file →
@@ -1,34 +1,53 @@
1 1 /**
2 - * Woo Archive Description widget behavior.
2 + * Woo Archive Description widget behaviour.
3 3 *
4 - * This widget is static; behavior is handled by WooCommerce/theme templates.
5 - * We keep an Elementor hook to ensure correct initialization in the editor.
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.
6 7 */
7 -(function ($) {
8 - "use strict";
8 +(function () {
9 + 'use strict';
9 10
10 - /**
11 - * Initialize widget instance.
12 - *
13 - * @param {Object} $scope Elementor scope.
14 - * @returns {void}
15 - */
16 - const initWooArchiveDescription = ($scope) => {
17 - void $scope;
18 - };
11 + const BOUND = 'kaArchiveDescriptionBound';
19 12
20 - $(window).on("elementor/frontend/init", function () {
21 - elementorFrontend.hooks.addAction(
22 - "frontend/element_ready/woo_archive_description.default",
23 - function ($scope) {
24 - initWooArchiveDescription($scope);
25 - }
26 - );
27 - });
28 -})(jQuery);
13 + const bind = (wrap) => {
14 + if (!wrap || !wrap.dataset || wrap.dataset[BOUND] === '1') {
15 + return;
16 + }
29 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 + }
30 24
25 + wrap.dataset[BOUND] = '1';
26 + const moreLabel = button.textContent;
27 + const lessLabel = button.dataset.lessText || '';
31 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 + };
32 39
40 + const init = (scope) => {
41 + const root = scope && scope.querySelectorAll ? scope : document;
42 + root.querySelectorAll('[data-ka-expandable="1"]').forEach(bind);
43 + };
33 44
45 + document.addEventListener('DOMContentLoaded', () => init(document));
34 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 +})();