PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.44
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.44
51.1.86 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 All 40 releases
king-addons / includes / extensions / Pricing_Table_Builder / assets / frontend.js

frontend.js in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.44, at includes/extensions/Pricing_Table_Builder/assets/frontend.js

91 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Pricing Table Builder - Frontend JavaScript
3 * Handles billing toggle and animations
4 */
5
6 (function() {
7 'use strict';
8
9 const KNG_PT = {
10 /**
11 * Initialize all pricing tables
12 */
13 init: function() {
14 document.querySelectorAll('.kng-pt-wrapper').forEach(wrapper => {
15 this.initToggle(wrapper);
16 });
17 },
18
19 /**
20 * Initialize billing toggle for a wrapper
21 */
22 initToggle: function(wrapper) {
23 const toggle = wrapper.querySelector('.kng-pt-toggle');
24 if (!toggle) return;
25
26 const buttons = toggle.querySelectorAll('.kng-pt-toggle-btn');
27 const cards = wrapper.querySelectorAll('.kng-pt-card');
28
29 buttons.forEach(btn => {
30 btn.addEventListener('click', (e) => {
31 e.preventDefault();
32 const period = btn.dataset.period;
33
34 // Update button states
35 buttons.forEach(b => {
36 b.classList.remove('is-active');
37 b.setAttribute('aria-checked', 'false');
38 });
39 btn.classList.add('is-active');
40 btn.setAttribute('aria-checked', 'true');
41
42 // Update wrapper data attribute
43 wrapper.dataset.period = period;
44
45 // Update price displays in each card
46 cards.forEach(card => {
47 this.updateCardPricing(card, period);
48 });
49 });
50 });
51 },
52
53 /**
54 * Update pricing display in a card
55 */
56 updateCardPricing: function(card, period) {
57 const priceGroups = card.querySelectorAll('.kng-pt-price-group');
58
59 priceGroups.forEach(group => {
60 if (group.dataset.period === period) {
61 group.style.display = '';
62 // Trigger animation
63 group.style.animation = 'none';
64 group.offsetHeight; // Force reflow
65 group.style.animation = '';
66 } else {
67 group.style.display = 'none';
68 }
69 });
70 },
71
72 /**
73 * Get current period for a wrapper
74 */
75 getCurrentPeriod: function(wrapper) {
76 return wrapper.dataset.period || 'monthly';
77 }
78 };
79
80 // Expose for admin preview
81 window.kngPTFrontend = KNG_PT;
82
83 // Initialize on DOM ready
84 if (document.readyState === 'loading') {
85 document.addEventListener('DOMContentLoaded', () => KNG_PT.init());
86 } else {
87 KNG_PT.init();
88 }
89
90 })();
91