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
king-addons / includes / widgets / Woo_Product_Short_Description / script.js

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

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