Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/bdthemes-element-pack/admin/assets/js/ep-builder.js

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + /* eslint-disable prettier/prettier */
2 + !(function ($) {
3 + 'use strict';
4 +
5 + function showModal() {
6 + $('#bdthemes-templates-builder-modal').show();
7 + }
8 +
9 + function hideModal() {
10 + $('#bdthemes-templates-builder-modal').hide();
11 + }
12 +
13 + function resetModalForm() {
14 + $('#bdthemes-templates-builder-modal form')[0].reset();
15 + $('#bdthemes-templates-builder-modal form .template_id').val('');
16 + }
17 +
18 + function setSubmitBtn(string) {
19 + $('#bdthemes-templates-builder-modal form .bdt-modal-submit-btn').val(
20 + string,
21 + );
22 + }
23 +
24 + function setError($this) {
25 + $this.addClass('input-error');
26 + }
27 +
28 + function removeError($this) {
29 + $('.input-error').removeClass('input-error');
30 + }
31 +
32 + function showUltimateStoreKitPopup(pageName) {
33 + // Create popup HTML
34 + var popupHtml = '<div id="bdt-ultimate-store-kit-popup" style="' +
35 + 'position: fixed;' +
36 + 'top: 0;' +
37 + 'left: 0;' +
38 + 'width: 100%;' +
39 + 'height: 100%;' +
40 + 'background: rgba(0,0,0,0.8);' +
41 + 'z-index: 99999;' +
42 + 'display: flex;' +
43 + 'align-items: center;' +
44 + 'justify-content: center;' +
45 + '">' +
46 + '<div style="' +
47 + 'background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);' +
48 + 'color: white;' +
49 + 'padding: 40px;' +
50 + 'border-radius: 15px;' +
51 + 'max-width: 500px;' +
52 + 'width: 90%;' +
53 + 'text-align: center;' +
54 + 'box-shadow: 0 20px 40px rgba(0,0,0,0.3);' +
55 + 'position: relative;' +
56 + '">' +
57 + '<button id="bdt-popup-close" style="' +
58 + 'position: absolute;' +
59 + 'top: 15px;' +
60 + 'right: 15px;' +
61 + 'background: rgba(255,255,255,0.2);' +
62 + 'border: none;' +
63 + 'color: white;' +
64 + 'width: 30px;' +
65 + 'height: 30px;' +
66 + 'border-radius: 50%;' +
67 + 'cursor: pointer;' +
68 + 'font-size: 18px;' +
69 + '">×</button>' +
70 + '<h2 style="margin: 0 0 20px 0; font-size: 28px;">🚀 Ultimate Store Kit</h2>' +
71 + '<h3 style="margin: 0 0 15px 0; color: #ffd700; font-size: 22px;">WooCommerce Dedicated Plugin</h3>' +
72 + '<p style="font-size: 16px; margin-bottom: 25px; line-height: 1.6;">' +
73 + 'For an enhanced WooCommerce experience, we highly recommend using the dedicated <strong>Ultimate Store Kit</strong> alongside this plugin.' +
74 + '</p>' +
75 + '<div style="' +
76 + 'background: rgba(255,255,255,0.1);' +
77 + 'padding: 20px;' +
78 + 'border-radius: 10px;' +
79 + 'margin: 20px 0;' +
80 + '">' +
81 + '<p style="margin: 0 0 15px 0; font-size: 14px;">' +
82 + 'The most powerful WooCommerce page builder for Elementor with 80+ widgets, advanced cart & checkout customization, and premium WooCommerce features.' +
83 + '</p>' +
84 + '<div style="display: flex; gap: 15px; justify-content: center; flex-wrap: wrap; margin-top: 20px;">' +
85 + '<a href="https://storekit.pro/" target="_blank" style="' +
86 + 'background: #ffd700;' +
87 + 'color: #333;' +
88 + 'padding: 12px 25px;' +
89 + 'text-decoration: none;' +
90 + 'border-radius: 25px;' +
91 + 'font-weight: bold;' +
92 + 'display: inline-block;' +
93 + 'transition: all 0.3s ease;' +
94 + '">Try Store Kit</a>' +
95 + '</div>' +
96 + '</div>' +
97 + '<p style="font-size: 12px; opacity: 0.9; margin: 15px 0 0 0;">' +
98 + '✨ Includes 80+ WooCommerce widgets • 🎨 Advanced page builder • 🛒 Cart & Checkout customization' +
99 + '</p>' +
100 + '</div>' +
101 + '</div>';
102 +
103 + // Add popup to body
104 + $('body').append(popupHtml);
105 +
106 + // Close popup handlers
107 + $('#bdt-popup-close, #bdt-ultimate-store-kit-popup').on('click', function(e) {
108 + if (e.target === this) {
109 + $('#bdt-ultimate-store-kit-popup').remove();
110 + }
111 + });
112 +
113 + // Close on escape key
114 + $(document).on('keyup.ultimateStoreKitPopup', function(e) {
115 + if (e.keyCode === 27) { // Escape key
116 + $('#bdt-ultimate-store-kit-popup').remove();
117 + $(document).off('keyup.ultimateStoreKitPopup');
118 + }
119 + });
120 + }
121 +
122 + function handleUltimateStoreKitPromotion($selectElement) {
123 + // WooCommerce promotional page options
124 + var promotionalOptions = [
125 + 'product|cart',
126 + 'product|checkout',
127 + 'product|myaccount',
128 + 'product|thankyou'
129 + ];
130 +
131 + var selectedValue = $selectElement.val();
132 +
133 + // Hide any existing promotional message
134 + $('.bdt-ultimate-store-kit-promotion').remove();
135 +
136 + // Check if selected option is a promotional WooCommerce page
137 + if (promotionalOptions.includes(selectedValue)) {
138 + var pageType = selectedValue.split('|')[1];
139 + var pageNames = {
140 + 'cart': 'Cart Page',
141 + 'checkout': 'Checkout Page',
142 + 'myaccount': 'My Account Page',
143 + 'thankyou': 'Thank You Page'
144 + };
145 +
146 + var pageName = pageNames[pageType] || pageType.charAt(0).toUpperCase() + pageType.slice(1);
147 +
148 + // Show promotional popup
149 + showUltimateStoreKitPopup(pageName);
150 +
151 + // Reset the select dropdown to previous state
152 + $selectElement.val('');
153 + } else {
154 + // Re-enable fields if not a promotional option
155 + $('#template_name').prop('disabled', false);
156 + $('.bdt-modal-submit-btn').prop('disabled', false);
157 +
158 + // Only clear template name if we're creating a new template (not editing)
159 + if ($('.template_id').val() === '') {
160 + $('#template_name').val('');
161 + $('.bdt-modal-submit-btn').val('Create Template');
162 + }
163 + }
164 + }
165 +
166 + $(document).on(
167 + 'click',
168 + '#bdthemes-templates-builder-modal .bdt-modal-close-button',
169 + function (e) {
170 + hideModal();
171 + },
172 + );
173 +
174 + $(document).on(
175 + 'click',
176 + 'body.post-type-bdt-template-builder a.page-title-action',
177 + function (e) {
178 + e.preventDefault();
179 + resetModalForm();
180 + setSubmitBtn('Create Template');
181 + showModal();
182 + },
183 + );
184 +
185 + $(document).on(
186 + 'submit',
187 + '#bdthemes-templates-builder-modal form',
188 + function (e) {
189 + e.preventDefault();
190 + var $serialized = $(this).serialize();
191 + removeError();
192 +
193 + $.ajax({
194 + url: ajaxurl,
195 + dataType: 'json',
196 + method: 'post',
197 + cache: false,
198 + data: {
199 + action: 'bdthemes_builder_create_template',
200 + data: $serialized,
201 + },
202 + success: function (response) {
203 + window.location.href = response.data.redirect;
204 + },
205 + error: function (errorThrown) {
206 + if (errorThrown.status == 422) {
207 + $.each(
208 + errorThrown.responseJSON.data.errors_arr,
209 + function (index, value) {
210 + setError($('#bdthemes-templates-builder-modal #' + index));
211 + },
212 + );
213 + }
214 + },
215 + });
216 + },
217 + );
218 +
219 + $(document).on(
220 + 'click',
221 + 'body.post-type-bdt-template-builder .row-actions .bdt-edit-action a',
222 + function (e) {
223 + e.preventDefault();
224 + removeError();
225 + resetModalForm();
226 + setSubmitBtn('Update Template');
227 +
228 + var templateId = 0;
229 + var parentColumn = $(this).parents(".column-title");
230 +
231 +
232 + $.ajax({
233 + url: ajaxurl,
234 + dataType: 'json',
235 + method: 'post',
236 + data: {
237 + action: 'bdthemes_builder_get_edit_template',
238 + template_id: $(this).data('id'),
239 + nonce: window.ElementPackConfigBuilder.nonce,
240 + },
241 + success: function (response) {
242 + if (response.success) {
243 + $('#bdthemes-templates-builder-modal form .template_id')
244 + .val(response.data.id)
245 + .change();
246 + $('#bdthemes-templates-builder-modal form #template_name')
247 + .val(response.data.name)
248 + .change();
249 + $('#bdthemes-templates-builder-modal form #template_type')
250 + .val(response.data.type)
251 + .change();
252 + $('#bdthemes-templates-builder-modal form #template_status')
253 + .val(response.data.status)
254 + .change();
255 +
256 + // if #template_type is themes|header or themes|footer then show the .bdt-header-footer-option-container
257 + if (response.data.type === 'themes|header' || response.data.type === 'themes|footer') {
258 + $('.bdt-header-footer-option-container').show();
259 + $('.bdt-template-modalinput-condition_a').val(response.data.condition_a).change();
260 + $('.bdt-template-modalinput-condition_singular').val(response.data.condition_singular).change();
261 + }
262 + }
263 +
264 + templateId = parentColumn.find(".hidden").attr("id").split("_")[1];
265 +
266 + var singularIdInput = $(".bdt-template-modalinput-condition_singular_id");
267 + $.ajax({
268 + url: window.ElementPackConfigBuilder.resturl + 'get-singular-list',
269 + dataType: "json",
270 + data: { ids: String(response.data.condition_singular_id) || "" },
271 + }).then(function (response) {
272 + if (response !== null && response.results.length > 0) {
273 + singularIdInput.html(" ");
274 + $.each(response.results, function (index, item) {
275 + var option = new Option(item.text, item.id, true, true);
276 + singularIdInput.append(option).trigger("change");
277 + });
278 + // singularIdInput.trigger({ type: "select2:select", params: { data: response } });
279 + }
280 + });
281 +
282 + showModal();
283 + },
284 + error: function (errorThrown) {
285 + // Handle error if needed
286 + },
287 + });
288 + },
289 + );
290 +
291 + $(document).ready(function () {
292 +
293 + $('#bdthemes-templates-builder-modal form #template_type').on('change', function () {
294 + if ($(this).val() === 'themes|header' || $(this).val() === 'themes|footer') {
295 + $('.bdt-header-footer-option-container').show();
296 + } else {
297 + $('.bdt-header-footer-option-container').hide();
298 + }
299 +
300 + // Handle Ultimate Store Kit promotional message
301 + handleUltimateStoreKitPromotion($(this));
302 + });
303 +
304 + $(".bdt-template-modalinput-condition_singular_id").select2({
305 + ajax: {
306 + url: window.ElementPackConfigBuilder.resturl + 'get-singular-list',
307 + dataType: "json",
308 + data: function (params) {
309 + return { s: params.term };
310 + },
311 + },
312 + cache: true,
313 + placeholder: "--",
314 + dropdownParent: $(".bdt-template-modalinput-condition_singular-container"),
315 + });
316 +
317 + $(document).on('change', '.bdt-template-modalinput-condition_a', function (e) {
318 + var selectedCondition = $(this).val();
319 + var singularContainer = $(".bdt-template-modalinput-condition_singular-container");
320 +
321 + if (selectedCondition === "singular") {
322 + singularContainer.show();
323 + } else {
324 + singularContainer.hide();
325 + }
326 + });
327 +
328 + $(".bdt-template-modalinput-condition_singular").on("change", function () {
329 + var selectedConditionSingular = $(this).val();
330 + var singularIdContainer = $(".bdt-template-modalinput-condition_singular_id-container");
331 +
332 + if (selectedConditionSingular === "selective") {
333 + singularIdContainer.show();
334 + } else {
335 + singularIdContainer.hide();
336 + }
337 + });
338 +
339 +
340 + });
341 +
342 + })(jQuery);
343 +