PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.1.2
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.1.2
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / assets / js / admin / theme-builder.js

theme-builder.js in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits 3.1.2, at assets/js/admin/theme-builder.js

1,425 lines 63.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function(){
2 var STYLE_ID = "jltma-dialog-styles";
3 var PORTAL_ID = "jltma-dialog-portal";
4 var CSS = [
5 /* z-index must beat the template-library uploader modal (999999)
6 and match the shared shadcn DialogOverlay/DialogContent convention
7 (9999999). The dialog is the topmost interactive layer in the admin,
8 so we anchor at one more order of magnitude to leave room underneath. */
9 ".jltma-dialog{position:fixed;inset:0;z-index:9999999;display:flex;align-items:center;justify-content:center;animation:jltma-dialog-fade-in 0.15s ease-out;}",
10 ".jltma-dialog__overlay{position:absolute;inset:0;background:rgba(15,23,42,0.55);backdrop-filter:blur(1.5px);-webkit-backdrop-filter:blur(1.5px);}",
11 '.jltma-dialog__content{position:relative;z-index:1;width:min(460px,calc(100% - 32px));background:var(--jltma-popover,#ffffff);color:var(--jltma-popover-foreground,#0f172a);border:1px solid var(--jltma-border,#e2e8f0);border-radius:var(--jltma-radius,10px);box-shadow:0 20px 48px rgba(15,23,42,0.24),0 8px 16px rgba(15,23,42,0.12);padding:24px;box-sizing:border-box;animation:jltma-dialog-scale-in 0.18s cubic-bezier(0.16,1,0.3,1);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;}',
12 ".jltma-dialog__title{margin:0 0 10px;font-size:18px;font-weight:600;line-height:1.35;letter-spacing:-0.01em;color:var(--jltma-foreground,#0f172a);}",
13 ".jltma-dialog__message{margin:0 0 24px;font-size:14px;line-height:1.55;color:var(--jltma-muted-foreground,#475569);white-space:pre-line;}",
14 ".jltma-dialog__actions{display:flex;justify-content:flex-end;gap:10px;flex-wrap:wrap;}",
15 ".jltma-dialog__btn{appearance:none;border:1px solid transparent;border-radius:calc(var(--jltma-radius,10px) - 2px);height:36px;padding:0 16px;font-size:13px;font-weight:600;line-height:1;cursor:pointer;transition:background-color 0.15s ease,border-color 0.15s ease,color 0.15s ease,box-shadow 0.15s ease,opacity 0.15s ease;font-family:inherit;display:inline-flex;align-items:center;justify-content:center;gap:6px;}",
16 ".jltma-dialog__btn:focus-visible{outline:2px solid var(--jltma-ring,rgba(104,20,205,0.45));outline-offset:2px;}",
17 ".jltma-dialog__btn:disabled{opacity:0.6;cursor:not-allowed;}",
18 ".jltma-dialog__btn--secondary{background:var(--jltma-background,#ffffff);border-color:var(--jltma-border,#e2e8f0);color:var(--jltma-foreground,#334155);}",
19 ".jltma-dialog__btn--secondary:hover:not(:disabled){background:var(--jltma-accent,#f1f5f9);border-color:var(--jltma-border,#cbd5e1);}",
20 ".jltma-dialog__btn--primary{background:var(--jltma-primary,#6814cd);color:var(--jltma-primary-foreground,#ffffff);}",
21 ".jltma-dialog__btn--primary:hover:not(:disabled){opacity:0.9;}",
22 ".jltma-dialog__btn--danger{background:var(--jltma-destructive,#dc2626);color:#ffffff;}",
23 ".jltma-dialog__btn--danger:hover:not(:disabled){opacity:0.9;}",
24 ".jltma-dialog__btn--success{background:#16a34a;color:#ffffff;}",
25 ".jltma-dialog__btn--success:hover:not(:disabled){opacity:0.9;}",
26 ".jltma-dialog__btn--warning{background:#d97706;color:#ffffff;}",
27 ".jltma-dialog__btn--warning:hover:not(:disabled){opacity:0.9;}",
28 ".jltma-dialog--loading .jltma-dialog__content{padding:32px 28px;width:min(340px,calc(100% - 32px));text-align:center;}",
29 ".jltma-dialog--loading .jltma-dialog__message{margin:0;color:var(--jltma-foreground,#0f172a);font-weight:500;font-size:14px;}",
30 ".jltma-dialog__spinner{width:36px;height:36px;border:3px solid var(--jltma-border,#e2e8f0);border-top-color:var(--jltma-primary,#6814cd);border-radius:50%;margin:0 auto 16px;animation:jltma-dialog-spin 0.8s linear infinite;}",
31 "@keyframes jltma-dialog-fade-in{from{opacity:0;}to{opacity:1;}}",
32 "@keyframes jltma-dialog-scale-in{from{opacity:0;transform:scale(0.94) translateY(4px);}to{opacity:1;transform:scale(1) translateY(0);}}",
33 "@keyframes jltma-dialog-spin{to{transform:rotate(360deg);}}"
34 ].join("");
35 function ensureStyles() {
36 if (typeof document === "undefined") return;
37 if (document.getElementById(STYLE_ID)) return;
38 var style = document.createElement("style");
39 style.id = STYLE_ID;
40 style.textContent = CSS;
41 document.head.appendChild(style);
42 }
43 function ensurePortal() {
44 var portal = document.getElementById(PORTAL_ID);
45 if (!portal) {
46 portal = document.createElement("div");
47 portal.id = PORTAL_ID;
48 document.body.appendChild(portal);
49 }
50 return portal;
51 }
52 function openDialog(opts) {
53 return new Promise(function(resolve) {
54 ensureStyles();
55 var portal = ensurePortal();
56 var tone = opts.tone || "primary";
57 var showCancel = !!opts.showCancel;
58 var root = document.createElement("div");
59 root.className = "jltma-dialog";
60 var overlay = document.createElement("div");
61 overlay.className = "jltma-dialog__overlay";
62 var content = document.createElement("div");
63 content.className = "jltma-dialog__content jltma-dialog-tone-" + tone;
64 content.setAttribute("role", "alertdialog");
65 content.setAttribute("aria-modal", "true");
66 if (opts.title) {
67 var titleEl = document.createElement("h3");
68 titleEl.className = "jltma-dialog__title";
69 titleEl.textContent = opts.title;
70 content.appendChild(titleEl);
71 }
72 if (opts.message) {
73 var msgEl = document.createElement("p");
74 msgEl.className = "jltma-dialog__message";
75 msgEl.textContent = opts.message;
76 content.appendChild(msgEl);
77 }
78 var actions = document.createElement("div");
79 actions.className = "jltma-dialog__actions";
80 var cleanup = function(value) {
81 document.removeEventListener("keydown", onKey);
82 overlay.removeEventListener("click", onOverlay);
83 if (root.parentNode) root.parentNode.removeChild(root);
84 resolve(value);
85 };
86 var onKey = function(e) {
87 if (e.key === "Escape") {
88 e.preventDefault();
89 cleanup(false);
90 } else if (e.key === "Enter") {
91 e.preventDefault();
92 cleanup(true);
93 }
94 };
95 document.addEventListener("keydown", onKey);
96 var onOverlay = function() {
97 cleanup(false);
98 };
99 overlay.addEventListener("click", onOverlay);
100 if (showCancel) {
101 var cancelBtn = document.createElement("button");
102 cancelBtn.type = "button";
103 cancelBtn.className = "jltma-dialog__btn jltma-dialog__btn--secondary";
104 cancelBtn.textContent = opts.cancelText || "Cancel";
105 cancelBtn.addEventListener("click", function() {
106 cleanup(false);
107 });
108 actions.appendChild(cancelBtn);
109 }
110 var confirmBtn = document.createElement("button");
111 confirmBtn.type = "button";
112 confirmBtn.className = "jltma-dialog__btn jltma-dialog__btn--" + tone;
113 confirmBtn.textContent = opts.confirmText || "OK";
114 confirmBtn.addEventListener("click", function() {
115 cleanup(true);
116 });
117 actions.appendChild(confirmBtn);
118 content.appendChild(actions);
119 root.appendChild(overlay);
120 root.appendChild(content);
121 portal.appendChild(root);
122 try {
123 confirmBtn.focus({ preventScroll: true });
124 } catch (e) {
125 confirmBtn.focus();
126 }
127 });
128 }
129 function confirmDialog(options) {
130 var opts = options || {};
131 return openDialog({
132 title: opts.title || "Are you sure?",
133 message: opts.message || "",
134 confirmText: opts.confirmText || "Confirm",
135 cancelText: opts.cancelText || "Cancel",
136 tone: opts.tone || "primary",
137 showCancel: true
138 });
139 }
140 function alertDialog(options) {
141 var opts = options || {};
142 return openDialog({
143 title: opts.title || "Notice",
144 message: opts.message || "",
145 confirmText: opts.confirmText || "OK",
146 tone: opts.tone || "primary",
147 showCancel: false
148 });
149 }
150 function loadingDialog(options) {
151 var opts = options || {};
152 ensureStyles();
153 var portal = ensurePortal();
154 var root = document.createElement("div");
155 root.className = "jltma-dialog jltma-dialog--loading";
156 var overlay = document.createElement("div");
157 overlay.className = "jltma-dialog__overlay";
158 var content = document.createElement("div");
159 content.className = "jltma-dialog__content";
160 content.setAttribute("role", "status");
161 content.setAttribute("aria-live", "polite");
162 var spinner = document.createElement("div");
163 spinner.className = "jltma-dialog__spinner";
164 spinner.setAttribute("aria-hidden", "true");
165 content.appendChild(spinner);
166 var msgEl = document.createElement("p");
167 msgEl.className = "jltma-dialog__message";
168 msgEl.textContent = opts.message || "Working…";
169 content.appendChild(msgEl);
170 root.appendChild(overlay);
171 root.appendChild(content);
172 portal.appendChild(root);
173 var closed = false;
174 return {
175 close: function() {
176 if (closed) return;
177 closed = true;
178 if (root.parentNode) root.parentNode.removeChild(root);
179 },
180 setMessage: function(next) {
181 msgEl.textContent = next;
182 }
183 };
184 }
185 if (typeof window !== "undefined") {
186 window.JLTMA_Dialog = window.JLTMA_Dialog || {};
187 window.JLTMA_Dialog.confirm = confirmDialog;
188 window.JLTMA_Dialog.alert = alertDialog;
189 window.JLTMA_Dialog.loading = loadingDialog;
190 }
191 const dialog = { confirmDialog, alertDialog, loadingDialog };
192 (function($) {
193 "use strict";
194 var JLTMA_Toaster = {
195 container: null,
196 init: function() {
197 if (!this.container) {
198 this.container = $('<div class="jltma-toaster-container"></div>');
199 $("body").append(this.container);
200 }
201 },
202 show: function(message, type = "success", duration = 3e3) {
203 this.init();
204 var toaster = $(`
205 <div class="jltma-toaster ${type}">
206 <span class="jltma-toaster-icon ${type}-icon"></span>
207 <span class="jltma-toaster-content">${message}</span>
208 <button class="jltma-toaster-close"></button>
209 <div class="jltma-toaster-progress"></div>
210 </div>
211 `);
212 this.container.append(toaster);
213 toaster.find(".jltma-toaster-close").on("click", function() {
214 JLTMA_Toaster.dismiss(toaster);
215 });
216 if (duration > 0) {
217 setTimeout(function() {
218 JLTMA_Toaster.dismiss(toaster);
219 }, duration);
220 }
221 return toaster;
222 },
223 dismiss: function(toaster) {
224 toaster.addClass("jltma-toaster-exit");
225 setTimeout(function() {
226 toaster.remove();
227 }, 300);
228 },
229 success: function(message, duration) {
230 return this.show(message, "success", duration);
231 },
232 error: function(message, duration) {
233 return this.show(message, "error", duration);
234 },
235 warning: function(message, duration) {
236 return this.show(message, "warning", duration);
237 },
238 info: function(message, duration) {
239 return this.show(message, "info", duration);
240 }
241 };
242 var TEMPLATE_TYPE_CONDITIONS = {
243 header: { rule: "entire_site", specific: "" },
244 footer: { rule: "entire_site", specific: "" },
245 comment: { rule: "singular", specific: "" },
246 single: { rule: "singular", specific: "post" },
247 archive: { rule: "archive", specific: "" },
248 category: { rule: "archive", specific: "category" },
249 tag: { rule: "archive", specific: "post_tag" },
250 author: { rule: "archive", specific: "author" },
251 date: { rule: "archive", specific: "date" },
252 page_single: { rule: "singular", specific: "page" },
253 search: { rule: "search", specific: "" },
254 "404": { rule: "404", specific: "" },
255 product: { rule: "singular", specific: "product" },
256 product_archive: { rule: "archive", specific: "product_cat" }
257 };
258 var isPremium = typeof JLTMACORE !== "undefined" && JLTMACORE.pro_conditions;
259 var proSuffix = isPremium ? "" : " (Pro)";
260 var freeTemplateTypes = ["header", "footer", "comment"];
261 function buildConditionRowHTML(index) {
262 var woocommerceOptions = "";
263 if (typeof masteraddons !== "undefined" && masteraddons.woocommerce_active) {
264 woocommerceOptions = ' <option value="product">Product' + proSuffix + '</option> <option value="product_archive">Product Archive' + proSuffix + "</option> ";
265 }
266 var lockBadge = isPremium ? "" : '<span class="jltma-lock-badge"><svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 24 24" fill="currentColor"><path d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zM9 8V6c0-1.66 1.34-3 3-3s3 1.34 3 3v2H9z"/></svg></span>';
267 var removeTitle = isPremium ? "Remove Condition" : "Pro Feature";
268 var removeClass = isPremium ? "jltma-remove-condition" : "jltma-remove-condition jltma-pro-locked";
269 return ' <div class="jltma-condition-row" data-index="' + index + '"> <div class="jltma-condition-controls"> <div class="jltma-condition-field"> <select name="jltma_condition_type[]" class="jltma-condition-select jltma-condition-type"> <option value="include">Include</option> <option value="exclude">Exclude' + proSuffix + '</option> </select> </div> <div class="jltma-condition-field"> <select name="jltma_condition_rule[]" class="jltma-condition-select jltma-condition-rule"> <option value="entire_site">Entire Site</option> <option value="front_page">Front Page' + proSuffix + '</option> <option value="singular">Singular' + proSuffix + '</option> <option value="archive">Archive' + proSuffix + '</option> <option value="search">Search' + proSuffix + '</option> <option value="404">404 Page' + proSuffix + "</option> " + woocommerceOptions + ' </select> </div> <div class="jltma-condition-field jltma-condition-specific-field" style="display: none;"> <select name="jltma_condition_specific[]" class="jltma-condition-select jltma-condition-specific-select"> <option value="">All</option> </select> </div> <button type="button" class="' + removeClass + '" title="' + removeTitle + '"> <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg> ' + lockBadge + " </button> </div> </div> ";
270 }
271 var Master_Header_Footer = {
272 Url_Param_Replace: function(url, paramName, paramValue) {
273 if (paramValue == null) {
274 paramValue = "";
275 }
276 var pattern = new RegExp("\\b(" + paramName + "=).*?(&|#|$)");
277 if (url.search(pattern) >= 0) {
278 return url.replace(pattern, "$1" + paramValue + "$2");
279 }
280 url = url.replace(/[?#]$/, "");
281 return url + (url.indexOf("?") > 0 ? "&" : "?") + paramName + "=" + paramValue;
282 },
283 JLTMA_Template_Editor: function(data) {
284 try {
285 (function($2) {
286 $2(".jltma_hf_modal-title").val(data.title);
287 var typeSelect = $2(".jltma_hfc_type");
288 typeSelect.val(data.type || "header");
289 typeSelect.trigger("change");
290 var activation_input = $2(".jltma-enable-switcher");
291 if (data.activation == "yes") {
292 activation_input.prop("checked", true);
293 } else {
294 activation_input.prop("checked", false);
295 }
296 activation_input.trigger("change");
297 $2("#jltma-conditions-repeater").empty();
298 let conditionData = [];
299 if (data.conditions_data && Array.isArray(data.conditions_data) && data.conditions_data.length > 0) {
300 conditionData = data.conditions_data;
301 } else {
302 if (data.jltma_hf_conditions && data.jltma_hf_conditions !== "entire_site") {
303 let specificValue = "";
304 let posts = [];
305 if (data.jltma_hf_conditions === "singular") {
306 if (data.jltma_hfc_singular === "selective" && data.jltma_hfc_singular_id) {
307 specificValue = data.jltma_hfc_singular_id;
308 }
309 } else if (data.jltma_hf_conditions === "archive") {
310 if (data.jltma_hfc_post_types_id) {
311 specificValue = data.jltma_hfc_post_types_id;
312 }
313 }
314 conditionData.push({
315 type: "include",
316 rule: data.jltma_hf_conditions,
317 specific: specificValue,
318 posts
319 });
320 } else {
321 conditionData.push({
322 type: "include",
323 rule: "entire_site",
324 specific: "",
325 posts: []
326 });
327 }
328 }
329 let maxConditionIndex = 0;
330 conditionData.forEach(function(condition, index) {
331 let woocommerceOptions = "";
332 if (typeof masteraddons !== "undefined" && masteraddons.woocommerce_active) {
333 woocommerceOptions = `
334 <option value="product">Product${proSuffix}</option>
335 <option value="product_archive">Product Archive${proSuffix}</option>
336 `;
337 }
338 const _removeClass = isPremium ? "jltma-remove-condition" : "jltma-remove-condition jltma-pro-locked";
339 const _removeTitle = isPremium ? "Remove Condition" : "Pro Feature";
340 const _lockBadge = isPremium ? "" : '<span class="jltma-lock-badge"><svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 24 24" fill="currentColor"><path d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zM9 8V6c0-1.66 1.34-3 3-3s3 1.34 3 3v2H9z"/></svg></span>';
341 const newRow = `
342 <div class="jltma-condition-row" data-index="${index}">
343 <div class="jltma-condition-controls">
344 <div class="jltma-condition-field">
345 <select name="jltma_condition_type[]" class="jltma-condition-select jltma-condition-type">
346 <option value="include" ${condition.type === "include" ? "selected" : ""}>Include</option>
347 <option value="exclude" ${condition.type === "exclude" ? "selected" : ""}>Exclude${proSuffix}</option>
348 </select>
349 </div>
350 <div class="jltma-condition-field">
351 <select name="jltma_condition_rule[]" class="jltma-condition-select jltma-condition-rule">
352 <option value="entire_site" ${condition.rule === "entire_site" ? "selected" : ""}>Entire Site</option>
353 <option value="front_page" ${condition.rule === "front_page" ? "selected" : ""}>Front Page${proSuffix}</option>
354 <option value="singular" ${condition.rule === "singular" ? "selected" : ""}>Singular${proSuffix}</option>
355 <option value="archive" ${condition.rule === "archive" ? "selected" : ""}>Archive${proSuffix}</option>
356 <option value="search" ${condition.rule === "search" ? "selected" : ""}>Search${proSuffix}</option>
357 <option value="404" ${condition.rule === "404" ? "selected" : ""}>404 Page${proSuffix}</option>
358 ${woocommerceOptions}
359 </select>
360 </div>
361 <div class="jltma-condition-field jltma-condition-specific-field" style="${condition.rule === "singular" || condition.rule === "archive" ? "display: block;" : "display: none;"}">
362 <select name="jltma_condition_specific[]" class="jltma-condition-select jltma-condition-specific-select">
363 <option value="">All</option>
364 </select>
365 </div>
366 <button type="button" class="${_removeClass}" title="${_removeTitle}">
367 <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>
368 ${_lockBadge}
369 </button>
370 </div>
371 </div>
372 `;
373 $2("#jltma-conditions-repeater").append(newRow);
374 const addedRow = $2("#jltma-conditions-repeater").find(".jltma-condition-row").last();
375 const specificSelect = addedRow.find(
376 ".jltma-condition-specific-select"
377 );
378 if (condition.rule === "singular") {
379 Master_Header_Footer.Load_Post_Types(specificSelect);
380 if (condition.specific) {
381 setTimeout(function() {
382 specificSelect.val(condition.specific);
383 }, 200);
384 if (condition.posts && condition.posts.length > 0) {
385 setTimeout(function() {
386 specificSelect.trigger("change");
387 addedRow.data("selected-posts", condition.posts);
388 setTimeout(function() {
389 Master_Header_Footer.populatePostSelection(
390 addedRow,
391 condition.posts
392 );
393 }, 800);
394 }, 300);
395 }
396 }
397 } else if (condition.rule === "archive") {
398 Master_Header_Footer.Load_Archive_Types(specificSelect);
399 if (condition.specific) {
400 setTimeout(function() {
401 specificSelect.val(condition.specific);
402 }, 200);
403 }
404 }
405 maxConditionIndex = Math.max(maxConditionIndex, index + 1);
406 });
407 if (typeof window.masterHeaderFooterConditionIndex !== "undefined") {
408 window.masterHeaderFooterConditionIndex = maxConditionIndex + 1;
409 }
410 $2(".jltma_hf_modal-jltma_hf_conditions").val(
411 data.jltma_hf_conditions
412 );
413 $2(".jltma_hf_modal-jltma_hfc_singular").val(data.jltma_hfc_singular);
414 $2(".jltma_hf_modal-jltma_hfc_singular_id").val(
415 data.jltma_hfc_singular_id
416 );
417 $2(".jltma_hf_conditions").val(data.jltma_hf_conditions);
418 $2(".jltma_hf_modal-jltma_hfc_post_types_id").val(
419 data.jltma_hfc_post_types_id
420 );
421 $2(".jltma-enable-switcher, .jltma_hfc_type").trigger("change");
422 })(jQuery);
423 } catch (e) {
424 }
425 },
426 Modal_Singular_List: function() {
427 $(".jltma_hf_modal-jltma_hfc_singular_id").select2({
428 ajax: {
429 url: window.masteraddons.resturl + "select2/singular_list",
430 type: "get",
431 dataType: "json",
432 headers: {
433 "X-WP-Nonce": window.masteraddons.rest_nonce
434 },
435 data: function(params) {
436 var query = {
437 s: params.term
438 };
439 return query;
440 }
441 },
442 cache: true,
443 placeholder: "Search for posts/pages...",
444 dropdownParent: $("#jltma_hf_modal_body")
445 });
446 this.Setup_Condition_Search();
447 },
448 Setup_Condition_Search: function() {
449 try {
450 } catch (e) {
451 console.error("Error in legacy Setup_Condition_Search:", e);
452 }
453 },
454 Modal_Submit: function() {
455 try {
456 (function($2) {
457 $2(document).on("keydown", ".jltma_hf_modal-title", function(e) {
458 if (e.key === "Enter" || e.keyCode === 13) {
459 e.preventDefault();
460 return false;
461 }
462 });
463 $2("#jltma_hf_modal_form").on("submit", function(e) {
464 e.preventDefault();
465 $2(".jltma-validation-message").remove();
466 var validationResult = Master_Header_Footer.Validate_Conditions();
467 if (!validationResult.valid) {
468 var validationHtml = '<div class="jltma-validation-message jltma-validation-message--error">' + validationResult.message + "</div>";
469 $2(".jltma-tab-conditions .jltma-conditions-section").prepend(
470 validationHtml
471 );
472 if (!$2(".jltma-tab-conditions").hasClass("active")) {
473 $2(".jltma-tab-button").removeClass("active");
474 $2(".jltma-tab-content").removeClass("active");
475 $2('.jltma-tab-button[data-tab="conditions"]').addClass(
476 "active"
477 );
478 $2(".jltma-tab-conditions").addClass("active");
479 }
480 $2(".jltma-tab-conditions").scrollTop(0);
481 return false;
482 }
483 var modal = $2("#jltma_hf_modal");
484 modal.addClass("loading");
485 var form_data = $2(this).serialize(), id = $2(this).attr("data-jltma-hf-id"), jltma_hfc_nonce = $2(this).attr("data-nonce"), open_editor = $2(this).attr("data-open-editor"), admin_url = $2(this).attr("data-editor-url");
486 $2.ajax({
487 url: window.masteraddons.resturl + "ma-template/update/" + id,
488 data: form_data,
489 type: "get",
490 dataType: "json",
491 headers: {
492 "X-WP-Nonce": jltma_hfc_nonce
493 },
494 success: function(output) {
495 setTimeout(function() {
496 modal.removeClass("loading");
497 }, 1500);
498 JLTMA_Toaster.success("Template saved successfully!");
499 var row = $2("#post-" + output.data.id);
500 if (row.length > 0) {
501 row.find(".column-type").html(output.data.type_html);
502 row.find(".column-condition").html(output.data.cond_text);
503 row.find(".row-title").html(output.data.title).attr("aria-label", output.data.title);
504 }
505 $2("#jltma_hf_modal").removeClass("jltma-modal-open");
506 if (open_editor == "1") {
507 window.location.href = admin_url + "?post=" + output.data.id + "&action=elementor";
508 } else if (id == "0") {
509 location.reload();
510 }
511 },
512 error: function(xhr, status, error) {
513 modal.removeClass("loading");
514 var errorMessage = "An error occurred while saving the template.";
515 if (xhr.responseJSON && xhr.responseJSON.message) {
516 errorMessage = xhr.responseJSON.message;
517 } else if (xhr.responseText) {
518 try {
519 var response = JSON.parse(xhr.responseText);
520 if (response.message) {
521 errorMessage = response.message;
522 }
523 } catch (e2) {
524 }
525 }
526 $2(".jltma-validation-message").remove();
527 var errorHtml = '<div class="jltma-validation-message jltma-validation-message--error">' + errorMessage + "</div>";
528 $2(".jltma-tab-conditions .jltma-conditions-section").prepend(
529 errorHtml
530 );
531 if (!$2(".jltma-tab-conditions").hasClass("active")) {
532 $2(".jltma-tab-button").removeClass("active");
533 $2(".jltma-tab-content").removeClass("active");
534 $2('.jltma-tab-button[data-tab="conditions"]').addClass(
535 "active"
536 );
537 $2(".jltma-tab-conditions").addClass("active");
538 }
539 console.error("Template save error:", error);
540 JLTMA_Toaster.error(
541 "Failed to save template. Please try again."
542 );
543 }
544 });
545 });
546 })(jQuery);
547 } catch (e) {
548 }
549 },
550 Open_Editor: function() {
551 try {
552 (function($2) {
553 $2(".jltma-btn-editor").on("click", function(e) {
554 var form = $2("#jltma_hf_modal_form");
555 form.attr("data-open-editor", "1");
556 form.trigger("submit");
557 });
558 })(jQuery);
559 } catch (e) {
560 }
561 },
562 Choose_Template_Singular_Condition: function() {
563 try {
564 (function($2) {
565 $2(".jltma_hf_modal-jltma_hfc_singular").on("change", function() {
566 var jltma_hfc_singular = $2(this).val();
567 var inputs = $2(".jltma_hf_modal-jltma_hfc_singular_id-container");
568 if (jltma_hfc_singular == "selective") {
569 inputs.show();
570 } else {
571 inputs.hide();
572 }
573 });
574 })(jQuery);
575 } catch (e) {
576 }
577 },
578 Choose_Template_Post_Types_Condition: function() {
579 try {
580 (function($2) {
581 $2(".jltma_hf_modal-jltma_hf_conditions").on("change", function() {
582 var jltma_hfc_singular = $2(this).val();
583 var inputs = $2(".jltma_hf_modal-jltma_hfc_post_types_id-container");
584 if (jltma_hfc_singular == "post_types") {
585 inputs.show();
586 } else {
587 inputs.hide();
588 }
589 });
590 })(jQuery);
591 } catch (e) {
592 }
593 },
594 Choose_Template_Conditions: function() {
595 try {
596 (function($2) {
597 $2(".jltma_hf_modal-jltma_hf_conditions").unbind().on("change", function() {
598 var jltma_hf_conditions = $2(this).val(), inputs = $2(".jltma_hf_modal-jltma_hfc_singular-container");
599 if (jltma_hf_conditions == "singular") {
600 inputs.show();
601 } else if (jltma_hf_conditions == "jltma-hfc-single-pro" || jltma_hf_conditions == "post_types_pro" || jltma_hf_conditions == "jltma-hfc-archive-pro" || jltma_hf_conditions == "search_pro" || jltma_hf_conditions == "404_pro" || jltma_hf_conditions == "product_pro" || jltma_hf_conditions == "product_archive_pro") {
602 $2(".jltma-hfc-popup-upgade").remove();
603 $2(".jltma_hf_modal-jltma_hf_conditions").after(
604 '<div class="jltma-hfc-popup-upgade"> ' + masteraddons.upgrade_pro + "</div>"
605 );
606 } else {
607 inputs.hide();
608 $2(".jltma-hfc-popup-upgade").hide();
609 }
610 });
611 })(jQuery);
612 } catch (e) {
613 }
614 },
615 Choose_Template_Type: function() {
616 try {
617 (function($2) {
618 function toggleProTypeLock(type) {
619 var isProType = !isPremium && freeTemplateTypes.indexOf(type) === -1;
620 var $activation = $2(".jtlma-mega-switcher");
621 var $footer = $2(".jltma-modal-footer");
622 if (isProType) {
623 $activation.addClass("jltma-pro-type-locked");
624 $activation.find(".jltma-enable-switcher").prop("disabled", true).prop("checked", false);
625 $footer.hide();
626 var noticeHTML = '<span class="jltma-badge-pro">Pro</span> <span>This template type requires Pro. <a href="#" class="jltma-pro-type-upgrade">Upgrade Now</a></span>';
627 if (!$2("#jltma-pro-type-notice-general").length) {
628 $activation.after('<div id="jltma-pro-type-notice-general" class="jltma-pro-type-notice">' + noticeHTML + "</div>");
629 }
630 if (!$2("#jltma-pro-type-notice-conditions").length) {
631 $2(".jltma-conditions-section").append('<div id="jltma-pro-type-notice-conditions" class="jltma-pro-type-notice">' + noticeHTML + "</div>");
632 }
633 } else {
634 $activation.removeClass("jltma-pro-type-locked");
635 $activation.find(".jltma-enable-switcher").prop("disabled", false);
636 $footer.show();
637 $2("#jltma-pro-type-notice-general, #jltma-pro-type-notice-conditions").remove();
638 }
639 }
640 $2(".jltma_hfc_type").on("change", function() {
641 var type = $2(this).val(), label = $2(".jltma-hfc-hide-item-label"), inputs = $2(".jltma_hf_options_container");
642 if (type == "section" || type == "comment") {
643 inputs.hide();
644 label.hide();
645 $2(".jltma-modal-footer").show();
646 $2('.jltma-tab-button[data-tab="conditions"]').show();
647 } else {
648 label.show();
649 inputs.show();
650 $2(".jltma-modal-footer").show();
651 $2('.jltma-tab-button[data-tab="conditions"]').show();
652 }
653 toggleProTypeLock(type);
654 Master_Header_Footer.Auto_Populate_Condition(type);
655 });
656 $2(document).on("click", ".jltma-pro-type-upgrade", function(e) {
657 e.preventDefault();
658 $2(".jltma-upgrade-popup").fadeIn(200);
659 });
660 })(jQuery);
661 } catch (e) {
662 }
663 },
664 Auto_Populate_Condition: function(templateType) {
665 var mapping = TEMPLATE_TYPE_CONDITIONS[templateType];
666 if (!mapping) {
667 return;
668 }
669 var repeater = jQuery("#jltma-conditions-repeater");
670 var modalId = jQuery("#jltma_hf_modal form").attr("data-jltma-hf-id");
671 if (modalId && parseInt(modalId, 10) > 0) {
672 return;
673 }
674 window.masterHeaderFooterConditionIndex = window.masterHeaderFooterConditionIndex || 1;
675 repeater.empty();
676 var newRow = buildConditionRowHTML(window.masterHeaderFooterConditionIndex);
677 repeater.append(newRow);
678 window.masterHeaderFooterConditionIndex++;
679 var rowElement = repeater.find(".jltma-condition-row").last();
680 rowElement.find(".jltma-condition-type").val("include");
681 rowElement.find(".jltma-condition-rule").val(mapping.rule);
682 var specificField = rowElement.find(".jltma-condition-specific-field");
683 var specificSelect = rowElement.find(".jltma-condition-specific-select");
684 if (mapping.rule === "singular") {
685 specificField.show();
686 specificSelect.empty().append('<option value="">All</option>');
687 Master_Header_Footer.Load_Post_Types(specificSelect);
688 if (mapping.specific) {
689 setTimeout(function() {
690 specificSelect.val(mapping.specific);
691 }, 200);
692 }
693 } else if (mapping.rule === "archive") {
694 specificField.show();
695 specificSelect.empty().append('<option value="">All</option>');
696 Master_Header_Footer.Load_Archive_Types(specificSelect);
697 if (mapping.specific) {
698 setTimeout(function() {
699 specificSelect.val(mapping.specific);
700 }, 200);
701 }
702 } else {
703 specificField.hide();
704 }
705 repeater.show();
706 },
707 Conditions_Repeater: function() {
708 try {
709 (function($2) {
710 window.masterHeaderFooterConditionIndex = window.masterHeaderFooterConditionIndex || 1;
711 $2(document).on("click", "#jltma-add-condition", function(e) {
712 if (!isPremium) {
713 e.preventDefault();
714 $2(".jltma-upgrade-popup").fadeIn(200);
715 return;
716 }
717 const repeater = $2("#jltma-conditions-repeater");
718 const newRow = buildConditionRowHTML(window.masterHeaderFooterConditionIndex);
719 repeater.append(newRow);
720 window.masterHeaderFooterConditionIndex++;
721 repeater.show();
722 const newRowElement = repeater.find(".jltma-condition-row").last();
723 newRowElement.find(".jltma-condition-rule").trigger("change");
724 });
725 $2(document).on("click", ".jltma-remove-condition", function(e) {
726 if (!isPremium) {
727 e.preventDefault();
728 $2(".jltma-upgrade-popup").fadeIn(200);
729 return;
730 }
731 const row = $2(this).closest(".jltma-condition-row");
732 const repeater = $2("#jltma-conditions-repeater");
733 row.remove();
734 if (repeater.find(".jltma-condition-row").length === 0) {
735 repeater.hide();
736 }
737 });
738 $2(document).on("change", ".jltma-condition-rule", function() {
739 const row = $2(this).closest(".jltma-condition-row");
740 const specificField = row.find(".jltma-condition-specific-field");
741 const specificSelect = row.find(".jltma-condition-specific-select");
742 const value = $2(this).val();
743 $2(".jltma-validation-message").remove();
744 row.find(
745 ".jltma-condition-type, .jltma-condition-rule, .jltma-condition-specific-select"
746 ).removeClass("jltma-field-error");
747 row.find(".jltma-condition-sub-select").each(function() {
748 if ($2(this).hasClass("select2-hidden-accessible")) {
749 $2(this).select2("destroy");
750 }
751 });
752 row.find(".jltma-condition-search-input").remove();
753 row.find(".jltma-condition-sub-select").remove();
754 row.find(".select2-hidden-accessible").each(function() {
755 $2(this).select2("destroy");
756 });
757 specificSelect.empty().append('<option value="">All</option>');
758 if (!isPremium && value !== "entire_site") {
759 specificField.hide();
760 } else if (value === "singular") {
761 specificField.show();
762 Master_Header_Footer.Load_Post_Types(specificSelect);
763 } else if (value === "archive") {
764 specificField.show();
765 Master_Header_Footer.Load_Archive_Types(specificSelect);
766 } else {
767 specificField.hide();
768 }
769 });
770 $2(document).on(
771 "change",
772 ".jltma-condition-specific-select",
773 function() {
774 const row = $2(this).closest(".jltma-condition-row");
775 const ruleSelect = row.find(".jltma-condition-rule");
776 const value = $2(this).val();
777 const selectElement = $2(this);
778 row.find(".jltma-condition-sub-select").each(function() {
779 if ($2(this).hasClass("select2-hidden-accessible")) {
780 $2(this).select2("destroy");
781 }
782 });
783 row.find(".jltma-condition-search-input").remove();
784 row.find(".jltma-condition-sub-select").remove();
785 if (ruleSelect.val() === "singular" && value && value !== "") {
786 const postTypeLabel = selectElement.find("option:selected").text();
787 const rowIndex = $2(
788 "#jltma-conditions-repeater .jltma-condition-row"
789 ).index(row);
790 const uniqueId = "post-select-" + Date.now() + "-" + Math.random().toString(36).substr(2, 9);
791 const postSelect = $2(`
792 <select name="jltma_condition_posts[${rowIndex}][]"
793 id="${uniqueId}"
794 class="jltma-form-control jltma-condition-sub-select"
795 data-post-type="${value}"
796 multiple>
797 </select>
798 `);
799 const removeButton = row.find(".jltma-remove-condition");
800 removeButton.before(postSelect);
801 setTimeout(function() {
802 postSelect.select2({
803 ajax: {
804 url: window.masteraddons.resturl + "select2/singular_list",
805 type: "get",
806 dataType: "json",
807 delay: 250,
808 headers: {
809 "X-WP-Nonce": window.masteraddons.rest_nonce
810 },
811 data: function(params) {
812 return {
813 s: params.term || "",
814 post_type: value
815 };
816 },
817 processResults: function(data, params) {
818 const results = [];
819 if (!params.term || params.term.length === 0) {
820 results.push({
821 id: "",
822 text: `All ${postTypeLabel}`
823 });
824 }
825 if (data && Array.isArray(data)) {
826 data.forEach((item) => {
827 results.push({
828 id: item.id,
829 text: item.text
830 });
831 });
832 }
833 return {
834 results
835 };
836 },
837 error: function(xhr, status, error) {
838 }
839 },
840 cache: true,
841 placeholder: `All ${postTypeLabel}`,
842 dropdownParent: $2("#jltma_hf_modal_body"),
843 allowClear: true,
844 multiple: true,
845 minimumInputLength: 0,
846 escapeMarkup: function(markup) {
847 return markup;
848 },
849 language: {
850 inputTooShort: function() {
851 return `Select specific ${postTypeLabel.toLowerCase()} or leave empty for all`;
852 },
853 noResults: function() {
854 return `No ${postTypeLabel.toLowerCase()} found`;
855 },
856 searching: function() {
857 return `Searching ${postTypeLabel.toLowerCase()}...`;
858 }
859 }
860 });
861 const savedPosts = row.data("selected-posts");
862 if (savedPosts && savedPosts.length > 0) {
863 setTimeout(function() {
864 Master_Header_Footer.populatePostSelection(
865 row,
866 savedPosts
867 );
868 }, 300);
869 }
870 }, 100);
871 }
872 }
873 );
874 $2(document).on(
875 "change",
876 ".jltma-condition-type, .jltma-condition-specific-select",
877 function() {
878 $2(".jltma-validation-message").remove();
879 $2(this).removeClass("jltma-field-error");
880 }
881 );
882 })(jQuery);
883 } catch (e) {
884 }
885 },
886 Load_Post_Types: function(selectElement) {
887 try {
888 $.ajax({
889 url: window.masteraddons.resturl + "ma-template/post-types",
890 type: "GET",
891 headers: {
892 "X-WP-Nonce": window.masteraddons.rest_nonce
893 },
894 success: function(postTypes) {
895 if (postTypes && Array.isArray(postTypes)) {
896 postTypes.forEach(function(postType) {
897 selectElement.append(
898 `<option value="${postType.value}">${postType.label}</option>`
899 );
900 });
901 }
902 },
903 error: function() {
904 const fallbackTypes = [
905 { value: "post", label: "Post" },
906 { value: "page", label: "Page" }
907 ];
908 if (typeof masteraddons !== "undefined" && masteraddons.woocommerce_active) {
909 fallbackTypes.push({ value: "product", label: "Product" });
910 }
911 fallbackTypes.forEach(function(postType) {
912 selectElement.append(
913 `<option value="${postType.value}">${postType.label}</option>`
914 );
915 });
916 }
917 });
918 } catch (e) {
919 console.error("Error loading post types:", e);
920 }
921 },
922 Load_Archive_Types: function(selectElement) {
923 try {
924 $.ajax({
925 url: window.masteraddons.resturl + "ma-template/archive-types",
926 type: "GET",
927 headers: {
928 "X-WP-Nonce": window.masteraddons.rest_nonce
929 },
930 success: function(archiveTypes) {
931 if (archiveTypes && Array.isArray(archiveTypes)) {
932 archiveTypes.forEach(function(archiveType) {
933 selectElement.append(
934 `<option value="${archiveType.value}">${archiveType.label}</option>`
935 );
936 });
937 }
938 },
939 error: function() {
940 const fallbackTypes = [
941 { value: "author", label: "Author Archive" },
942 { value: "date", label: "Date Archive" },
943 { value: "category", label: "Category Archive" },
944 { value: "tag", label: "Tag Archive" }
945 ];
946 if (typeof masteraddons !== "undefined" && masteraddons.woocommerce_active) {
947 fallbackTypes.push({
948 value: "product_cat",
949 label: "Product Category"
950 });
951 fallbackTypes.push({
952 value: "product_tag",
953 label: "Product Tag"
954 });
955 }
956 fallbackTypes.forEach(function(archiveType) {
957 selectElement.append(
958 `<option value="${archiveType.value}">${archiveType.label}</option>`
959 );
960 });
961 }
962 });
963 } catch (e) {
964 console.error("Error loading archive types:", e);
965 }
966 },
967 Validate_Conditions: function() {
968 try {
969 var hasInclude = false;
970 var hasValidConditions = false;
971 var conditionRows = $(
972 "#jltma-conditions-repeater .jltma-condition-row"
973 );
974 var errors = [];
975 if (conditionRows.length === 0) {
976 return {
977 valid: true,
978 message: "No conditions set - template will not display anywhere until conditions are added."
979 };
980 }
981 conditionRows.each(function(index) {
982 var row = $(this);
983 var type = row.find(".jltma-condition-type").val();
984 var rule = row.find(".jltma-condition-rule").val();
985 var specific = row.find(".jltma-condition-specific-select").val();
986 var specificVisible = row.find(".jltma-condition-specific-select").is(":visible");
987 row.find(
988 ".jltma-condition-type, .jltma-condition-rule, .jltma-condition-specific-select"
989 ).removeClass("jltma-field-error");
990 if (!type) {
991 row.find(".jltma-condition-type").addClass("jltma-field-error");
992 errors.push("Condition type is required for row " + (index + 1));
993 }
994 if (!rule) {
995 row.find(".jltma-condition-rule").addClass("jltma-field-error");
996 errors.push("Condition rule is required for row " + (index + 1));
997 }
998 if (specificVisible && rule && (rule === "singular" || rule === "archive") && !specific) {
999 row.find(".jltma-condition-specific-select").addClass("jltma-field-error");
1000 errors.push(
1001 "Specific selection is required for " + rule + " condition in row " + (index + 1)
1002 );
1003 }
1004 if (type && rule) {
1005 hasValidConditions = true;
1006 if (type === "include") {
1007 hasInclude = true;
1008 }
1009 }
1010 });
1011 if (errors.length > 0) {
1012 return {
1013 valid: false,
1014 message: errors[0]
1015 // Show first error
1016 };
1017 }
1018 if (!hasValidConditions) {
1019 return {
1020 valid: false,
1021 message: "Please complete all condition fields."
1022 };
1023 }
1024 if (hasValidConditions && !hasInclude) {
1025 return {
1026 valid: false,
1027 message: 'At least one "Include" condition is required. Templates must include at least one location where they should be displayed.'
1028 };
1029 }
1030 var includeEntireSite = false;
1031 var hasOtherIncludes = false;
1032 conditionRows.each(function() {
1033 var type = $(this).find(".jltma-condition-type").val();
1034 var rule = $(this).find(".jltma-condition-rule").val();
1035 if (type === "include") {
1036 if (rule === "entire_site") {
1037 includeEntireSite = true;
1038 } else {
1039 hasOtherIncludes = true;
1040 }
1041 }
1042 });
1043 if (includeEntireSite && hasOtherIncludes) {
1044 return {
1045 valid: false,
1046 message: 'You cannot use "Entire Site" with other include conditions. "Entire Site" includes everything already.'
1047 };
1048 }
1049 return { valid: true };
1050 } catch (e) {
1051 console.error("Validation error:", e);
1052 return {
1053 valid: false,
1054 message: "Validation error occurred."
1055 };
1056 }
1057 },
1058 Modal_Add_Edit: function() {
1059 try {
1060 (function($2) {
1061 $2(document).on(
1062 "click",
1063 ".row-actions .edit a, .page-title-action:not(.jltma-cpt-btn), .column-title .row-title, .jltma-theme-builder-edit-cond",
1064 function(e) {
1065 e.preventDefault();
1066 var id = 0, modal = $2("#jltma_hf_modal"), jltma_hfc_nonce = $2("#jltma_hf_modal_form").attr("data-nonce"), parent = $2(this).parents(".column-title");
1067 modal.addClass("loading");
1068 modal.addClass("jltma-modal-open");
1069 var $clicked = $2(this).closest(".jltma-theme-builder-edit-cond");
1070 if ($clicked.length > 0) {
1071 id = $clicked.attr("id");
1072 } else if (parent.length > 0) {
1073 id = parent.find(".hidden").attr("id").split("_")[1];
1074 } else {
1075 id = 0;
1076 }
1077 if (id > 0) {
1078 $2.ajax({
1079 url: window.masteraddons.resturl + "ma-template/get/" + id,
1080 type: "get",
1081 headers: { "X-WP-Nonce": jltma_hfc_nonce },
1082 dataType: "json",
1083 success: function(data2) {
1084 Master_Header_Footer.JLTMA_Template_Editor(data2);
1085 modal.removeClass("loading");
1086 },
1087 error: function(xhr, status, error) {
1088 console.error("Error loading template data:", error);
1089 modal.removeClass("loading");
1090 var data2 = {
1091 title: "",
1092 type: "header",
1093 jltma_hf_conditions: "entire_site",
1094 jltma_hfc_singular: "all",
1095 activation: ""
1096 };
1097 Master_Header_Footer.JLTMA_Template_Editor(data2);
1098 }
1099 });
1100 } else {
1101 var data = {
1102 title: "",
1103 type: "header",
1104 jltma_hf_conditions: "entire_site",
1105 jltma_hfc_singular: "all",
1106 activation: ""
1107 };
1108 modal.removeClass("loading");
1109 }
1110 modal.find("form").attr("data-jltma-hf-id", id);
1111 let $select = $2(".jltma_hfc_type");
1112 let activeTabTitle = $2(
1113 ".master_type_filter_tab_container.nav-tab-wrapper .nav-tab-active"
1114 ).text().trim();
1115 if ($select.length && activeTabTitle) {
1116 $select.find("option").each(function() {
1117 let optionText = $2(this).text().trim();
1118 if (optionText.toLowerCase() === activeTabTitle.toLowerCase()) {
1119 if (!$select.val() || $select.val().toLowerCase() !== optionText.toLowerCase()) {
1120 $2(this).prop("selected", true);
1121 $select.trigger("change");
1122 }
1123 return false;
1124 }
1125 });
1126 }
1127 let $conditionsBtn = $2(".jltma-tab-button");
1128 if (["search", "404 page"].includes(activeTabTitle.toLowerCase())) {
1129 $conditionsBtn.remove();
1130 }
1131 let $ruleSelect = $2(
1132 ".jltma-condition-select.jltma-condition-rule"
1133 );
1134 function updateSelectOptions() {
1135 const activeTabTitle2 = $2(
1136 ".master_type_filter_tab_container .nav-tab-active"
1137 ).text().trim().toLowerCase();
1138 let visibleOptions = [];
1139 switch (activeTabTitle2) {
1140 case "all":
1141 visibleOptions = ["entire"];
1142 var data2 = {
1143 title: "",
1144 type: "header",
1145 jltma_hf_conditions: "entire_site",
1146 jltma_hfc_singular: "all",
1147 activation: ""
1148 };
1149 Master_Header_Footer.JLTMA_Template_Editor(data2);
1150 break;
1151 case "header":
1152 visibleOptions = ["entire"];
1153 var data2 = {
1154 title: "",
1155 type: "header",
1156 jltma_hf_conditions: "entire_site",
1157 jltma_hfc_singular: "all",
1158 activation: ""
1159 };
1160 Master_Header_Footer.JLTMA_Template_Editor(data2);
1161 break;
1162 case "footer":
1163 visibleOptions = ["entire"];
1164 var data2 = {
1165 title: "",
1166 type: "footer",
1167 jltma_hf_conditions: "entire_site",
1168 jltma_hfc_singular: "all",
1169 activation: ""
1170 };
1171 Master_Header_Footer.JLTMA_Template_Editor(data2);
1172 break;
1173 case "single":
1174 visibleOptions = ["singular"];
1175 data2 = {
1176 title: "",
1177 type: "single",
1178 jltma_hf_conditions: "singular",
1179 jltma_hfc_singular: "all",
1180 activation: ""
1181 };
1182 Master_Header_Footer.JLTMA_Template_Editor(data2);
1183 break;
1184 case "archive":
1185 visibleOptions = ["archive"];
1186 data2 = {
1187 title: "",
1188 type: "archive",
1189 jltma_hf_conditions: "archive",
1190 jltma_hfc_singular: "all",
1191 activation: ""
1192 };
1193 Master_Header_Footer.JLTMA_Template_Editor(data2);
1194 break;
1195 case "comment":
1196 visibleOptions = ["singular"];
1197 data2 = {
1198 title: "",
1199 type: "comment",
1200 jltma_hf_conditions: "singular",
1201 jltma_hfc_singular: "all",
1202 activation: ""
1203 };
1204 Master_Header_Footer.JLTMA_Template_Editor(data2);
1205 break;
1206 default:
1207 visibleOptions = $ruleSelect.find("option").map(function() {
1208 return $2(this).attr("value").toLowerCase();
1209 }).get();
1210 break;
1211 }
1212 $ruleSelect.find("option").each(function() {
1213 const optionValue = $2(this).attr("value").toLowerCase();
1214 if (visibleOptions.includes(optionValue)) {
1215 $2(this).show();
1216 if (!$ruleSelect.val() || !visibleOptions.includes($ruleSelect.val().toLowerCase())) {
1217 $ruleSelect.val($2(this).val());
1218 }
1219 } else {
1220 $2(this).hide();
1221 }
1222 });
1223 }
1224 $2(document).ready(function() {
1225 updateSelectOptions();
1226 });
1227 }
1228 );
1229 $2(".jltma-tab-button").on("click", function(e) {
1230 e.preventDefault();
1231 var targetTab = $2(this).data("tab");
1232 $2(".jltma-tab-button").removeClass("active");
1233 $2(".jltma-tab-content").removeClass("active");
1234 $2(this).addClass("active");
1235 $2(".jltma-tab-" + targetTab).addClass("active");
1236 });
1237 })(jQuery);
1238 } catch (e) {
1239 }
1240 },
1241 // Helper function to populate post selection dropdown
1242 populatePostSelection: function(row, selectedPosts) {
1243 try {
1244 const postSelect = row.find(".jltma-condition-sub-select");
1245 if (postSelect.length && postSelect.hasClass("select2-hidden-accessible")) {
1246 let postsArray = Array.isArray(selectedPosts) ? selectedPosts : [];
1247 postsArray = postsArray.map((id) => parseInt(id, 10)).filter((id) => !isNaN(id));
1248 if (postsArray.length > 0) {
1249 const postType = postSelect.data("post-type");
1250 $.ajax({
1251 url: window.masteraddons.resturl + "select2/singular_list",
1252 type: "get",
1253 dataType: "json",
1254 headers: {
1255 "X-WP-Nonce": window.masteraddons.rest_nonce
1256 },
1257 data: {
1258 s: "",
1259 // Empty search to get all
1260 post_type: postType,
1261 ids: postsArray.join(",")
1262 // Pass the IDs we need
1263 },
1264 success: function(data) {
1265 if (data && Array.isArray(data)) {
1266 data.forEach(function(item) {
1267 if (postsArray.includes(parseInt(item.id))) {
1268 const existingOption = postSelect.find(
1269 `option[value="${item.id}"]`
1270 );
1271 if (existingOption.length === 0) {
1272 const option = new Option(
1273 item.text,
1274 item.id,
1275 true,
1276 true
1277 );
1278 postSelect.append(option);
1279 } else {
1280 existingOption.prop("selected", true);
1281 }
1282 }
1283 });
1284 postSelect.val(postsArray).trigger("change");
1285 }
1286 },
1287 error: function(xhr, status, error) {
1288 postSelect.val(postsArray).trigger("change");
1289 }
1290 });
1291 }
1292 }
1293 } catch (error) {
1294 console.warn("Error populating post selection:", error);
1295 }
1296 }
1297 };
1298 jQuery(document).ready(function($2) {
1299 "use strict";
1300 $2(document).on(
1301 "click",
1302 ".jltma-pop-close, .close-btn, .jltma-modal-backdrop",
1303 function(e) {
1304 if ($2(e.target).hasClass("jltma-modal-backdrop") || $2(e.target).hasClass("close-btn") || $2(e.target).closest(".jltma-pop-close").length) {
1305 $2("#jltma_hf_modal").removeClass("jltma-modal-open");
1306 e.preventDefault();
1307 }
1308 }
1309 );
1310 var $themeAddNewBtn = $2(".wrap .page-title-action").first();
1311 if ($themeAddNewBtn.length) {
1312 $themeAddNewBtn.text("Add New Template");
1313 if (!$2(".jltma-theme-builder-tutorial").length) {
1314 $themeAddNewBtn.after(
1315 '<a href="https://www.youtube.com/watch?v=KmlHyER6uEQ" target="_blank" class="jltma-cpt-btn jltma-cpt-btn-youtube jltma-theme-builder-tutorial"><svg width="16" height="16" viewBox="0 0 24 24" fill="#ff0000"><path d="M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.546 12 3.546 12 3.546s-7.505 0-9.377.504A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.504 9.376.504 9.376.504s7.505 0 9.377-.504a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z"/></svg> Video Tutorial</a>'
1316 );
1317 }
1318 }
1319 $2(document).on("click", ".wrap .page-title-action:not(.jltma-cpt-btn)", function(e) {
1320 $2("#jltma_hf_modal").toggleClass("jltma-modal-open");
1321 e.preventDefault();
1322 });
1323 Master_Header_Footer.Modal_Add_Edit();
1324 Master_Header_Footer.Choose_Template_Type();
1325 Master_Header_Footer.Choose_Template_Conditions();
1326 Master_Header_Footer.Choose_Template_Singular_Condition();
1327 Master_Header_Footer.Choose_Template_Post_Types_Condition();
1328 Master_Header_Footer.Open_Editor();
1329 Master_Header_Footer.Modal_Submit();
1330 Master_Header_Footer.Modal_Singular_List();
1331 Master_Header_Footer.Conditions_Repeater();
1332 $2(document).on("click", ".jltma-copy-shortcode", function(e) {
1333 e.preventDefault();
1334 var shortcode = $2(this).data("shortcode");
1335 var button = $2(this);
1336 var originalIcon = button.find(".dashicons");
1337 if (navigator.clipboard && navigator.clipboard.writeText) {
1338 navigator.clipboard.writeText(shortcode).then(function() {
1339 originalIcon.removeClass("dashicons-clipboard").addClass("dashicons-yes-alt");
1340 button.css("background", "#46b450");
1341 JLTMA_Toaster.success("Shortcode copied to clipboard!", 2e3);
1342 setTimeout(function() {
1343 originalIcon.removeClass("dashicons-yes-alt").addClass("dashicons-clipboard");
1344 button.css("background", "#f9f9f9");
1345 }, 2e3);
1346 }).catch(function() {
1347 copyToClipboardFallback(shortcode, button, originalIcon);
1348 });
1349 } else {
1350 copyToClipboardFallback(shortcode, button, originalIcon);
1351 }
1352 });
1353 function copyToClipboardFallback(text, button, originalIcon) {
1354 var textarea = $2("<textarea>").css({
1355 position: "fixed",
1356 top: "0",
1357 left: "0",
1358 opacity: "0",
1359 pointerEvents: "none"
1360 }).val(text);
1361 $2("body").append(textarea);
1362 textarea[0].select();
1363 try {
1364 var success = document.execCommand("copy");
1365 if (success) {
1366 originalIcon.removeClass("dashicons-clipboard").addClass("dashicons-yes-alt");
1367 button.css("background", "#46b450");
1368 JLTMA_Toaster.success("Shortcode copied to clipboard!", 2e3);
1369 setTimeout(function() {
1370 originalIcon.removeClass("dashicons-yes-alt").addClass("dashicons-clipboard");
1371 button.css("background", "#f9f9f9");
1372 }, 2e3);
1373 } else {
1374 JLTMA_Toaster.error(
1375 "Failed to copy shortcode. Please copy manually.",
1376 3e3
1377 );
1378 }
1379 } catch (err) {
1380 JLTMA_Toaster.error("Copy not supported. Please copy manually.", 3e3);
1381 }
1382 textarea.remove();
1383 }
1384 var tab_container = $2(".wp-header-end"), tabs = "", proBadge = isPremium ? "" : ' <span class="jltma-badge-pro">Pro</span>', proTypes = ["single", "archive", "search", "404", "product", "product_archive"], filter_types = [
1385 { key: "all", label: "All" },
1386 { key: "header", label: "Header" },
1387 { key: "footer", label: "Footer" },
1388 { key: "comment", label: "Comment" },
1389 { key: "single", label: "Single" + proBadge },
1390 { key: "archive", label: "Archive" + proBadge },
1391 { key: "search", label: "Search" + proBadge },
1392 { key: "404", label: "404 Page" + proBadge }
1393 ];
1394 if (typeof masteraddons !== "undefined" && masteraddons.woocommerce_active) {
1395 filter_types.push({ key: "product", label: "Product" + proBadge });
1396 filter_types.push({ key: "product_archive", label: "Product Archive" + proBadge });
1397 }
1398 var url = new URL(window.location.href), s = url.searchParams.get("master_template_type_filter");
1399 s = s == null ? "all" : s;
1400 $2.each(filter_types, function(index, item) {
1401 var url2 = Master_Header_Footer.Url_Param_Replace(
1402 window.location.href,
1403 "master_template_type_filter",
1404 item.key
1405 );
1406 var jlma_class = s == item.key ? "master_type_filter_active nav-tab-active" : " ";
1407 var isProTab = !isPremium && proTypes.indexOf(item.key) !== -1;
1408 tabs += `
1409 <a href="${isProTab ? "#" : url2}" class="${jlma_class} master_type_filter_tab_item nav-tab${isProTab ? " jltma-pro-tab" : ""}"${isProTab ? ' data-pro="1"' : ""}>${item.label}</a>
1410 `;
1411 tabs += "\n";
1412 });
1413 tab_container.after(
1414 '<div class="master_type_filter_tab_container nav-tab-wrapper">' + tabs + "</div><br/>"
1415 );
1416 if (!isPremium) {
1417 $2(document).on("click", ".master_type_filter_tab_item[data-pro]", function(e) {
1418 e.preventDefault();
1419 $2(".jltma-upgrade-popup").fadeIn(200);
1420 });
1421 }
1422 });
1423 })(jQuery);
1424 })();
1425