PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.78
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.78
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 / extensions / Theme_Builder / script.js

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

135 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 document.addEventListener('DOMContentLoaded', () => {
2 const addNewButton = document.getElementById('ka-theme-builder-add-new');
3 const addNewEmptyButton = document.getElementById('ka-theme-builder-add-new-empty');
4 const addNewModal = document.getElementById('ka-theme-builder-modal');
5 const quickModal = document.getElementById('ka-theme-builder-quick-modal');
6 const closeButtons = document.querySelectorAll('.ka-tb-modal-close');
7
8 const isOpenClass = 'is-open';
9
10 const openModal = (modal) => {
11 if (!modal) return;
12 modal.classList.add(isOpenClass);
13 modal.setAttribute('aria-hidden', 'false');
14 };
15
16 const closeModal = (modal) => {
17 if (!modal) return;
18 modal.classList.remove(isOpenClass);
19 modal.setAttribute('aria-hidden', 'true');
20 };
21
22 if (addNewButton) {
23 addNewButton.addEventListener('click', (event) => {
24 event.preventDefault();
25 openModal(addNewModal);
26 });
27 }
28
29 if (addNewEmptyButton) {
30 addNewEmptyButton.addEventListener('click', (event) => {
31 event.preventDefault();
32 openModal(addNewModal);
33 });
34 }
35
36 // Type cards: preselect type/location and open create modal
37 const typeButtons = document.querySelectorAll('.ka-tb-type');
38 const typeSelect = document.getElementById('ka-tb-type');
39 const locationSelect = document.getElementById('ka-tb-location');
40 typeButtons.forEach((btn) => {
41 btn.addEventListener('click', (event) => {
42 event.preventDefault();
43 const type = btn.getAttribute('data-ka-tb-type');
44 const location = btn.getAttribute('data-ka-tb-location');
45
46 if (typeSelect && type) {
47 typeSelect.value = type;
48 }
49 if (locationSelect && location) {
50 locationSelect.value = location;
51 }
52 openModal(addNewModal);
53 });
54 });
55
56 closeButtons.forEach((button) => {
57 button.addEventListener('click', () => {
58 closeModal(addNewModal);
59 closeModal(quickModal);
60 });
61 });
62
63 const quickLinks = document.querySelectorAll('.ka-tb-quick-edit');
64 const quickPriority = document.getElementById('ka-tb-quick-priority');
65 const quickTemplateId = document.getElementById('ka-tb-quick-template-id');
66 const quickEnabled = document.getElementById('ka-tb-quick-enabled');
67
68 quickLinks.forEach((link) => {
69 link.addEventListener('click', (event) => {
70 event.preventDefault();
71 const templateId = link.getAttribute('data-template-id');
72 const priority = link.getAttribute('data-priority');
73 const enabled = link.getAttribute('data-enabled') === '1';
74
75 if (quickTemplateId) {
76 quickTemplateId.value = templateId || '';
77 }
78 if (quickPriority) {
79 quickPriority.value = priority || '10';
80 }
81 if (quickEnabled) {
82 quickEnabled.value = enabled ? '1' : '0';
83 }
84
85 openModal(quickModal);
86 });
87 });
88
89 // Backdrop click closes (clicking inside modal does not)
90 [addNewModal, quickModal].forEach((modal) => {
91 if (!modal) return;
92 modal.addEventListener('click', (event) => {
93 if (event.target === modal) {
94 closeModal(modal);
95 }
96 });
97 });
98
99 // ESC closes any open modal
100 document.addEventListener('keydown', (event) => {
101 if (event.key !== 'Escape') return;
102 closeModal(addNewModal);
103 closeModal(quickModal);
104 });
105
106 // Dropdown actions
107 const closeAllDropdowns = () => {
108 document.querySelectorAll('[data-ka-dropdown].is-open').forEach((dd) => dd.classList.remove('is-open'));
109 };
110
111 document.addEventListener('click', (event) => {
112 const trigger = event.target.closest('.ka-tb-dropdown-trigger');
113 if (trigger) {
114 const dropdown = trigger.closest('[data-ka-dropdown]');
115 if (!dropdown) return;
116
117 const isOpen = dropdown.classList.contains('is-open');
118 closeAllDropdowns();
119 dropdown.classList.toggle('is-open', !isOpen);
120 return;
121 }
122
123 // Click inside menu should not close immediately (links will navigate)
124 if (event.target.closest('.ka-tb-dropdown-menu')) {
125 return;
126 }
127
128 closeAllDropdowns();
129 });
130 });
131
132
133
134
135