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 / editor.js

editor.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/editor.js

737 lines 30.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function(){
2 !(function(e) {
3 "use strict";
4 var t, a, o, n, i = window.MasterAddonsData || {};
5 a = {
6 ModalLayoutView: null,
7 ModalHeaderView: null,
8 ModalHeaderInsertButton: null,
9 ModalLoadingView: null,
10 ModalBodyView: null,
11 ModalErrorView: null,
12 LibraryCollection: null,
13 KeywordsModel: null,
14 ModalCollectionView: null,
15 ModalTabsCollection: null,
16 ModalTabsCollectionView: null,
17 FiltersCollectionView: null,
18 FiltersItemView: null,
19 ModalTabsItemView: null,
20 ModalTemplateItemView: null,
21 ModalInsertTemplateBehavior: null,
22 ModalTemplateModel: null,
23 CategoriesCollection: null,
24 ModalPreviewView: null,
25 ModalHeaderBack: null,
26 ModalHeaderLogo: null,
27 MasterProButton: null,
28 KeywordsView: null,
29 TabModel: null,
30 CategoryModel: null,
31 init: function() {
32 var a2 = this;
33 a2.ModalTemplateModel = Backbone.Model.extend({
34 defaults: {
35 template_id: 0,
36 name: "",
37 title: "",
38 thumbnail: "",
39 preview: "",
40 source: "",
41 categories: [],
42 keywords: [],
43 liveUrl: "",
44 package: ""
45 }
46 }), a2.ModalHeaderView = Marionette.LayoutView.extend({
47 id: "ma-el-template-modal-header",
48 template: "#views-ma-el-template-modal-header",
49 ui: {
50 closeModal: "#ma-el-template-modal-header-close-modal"
51 },
52 events: {
53 "click @ui.closeModal": "onCloseModalClick"
54 },
55 regions: {
56 headerLogo: "#ma-el-template-modal-header-logo-area",
57 headerTabs: "#ma-el-template-modal-header-tabs",
58 headerActions: "#ma-el-template-modal-header-actions"
59 },
60 onCloseModalClick: function() {
61 e("body").removeClass("elementor-editor-preview").addClass("elementor-editor-active");
62 t.closeModal();
63 }
64 }), a2.TabModel = Backbone.Model.extend({
65 defaults: {
66 slug: "",
67 title: ""
68 }
69 }), a2.LibraryCollection = Backbone.Collection.extend({
70 model: a2.ModalTemplateModel
71 }), a2.ModalTabsCollection = Backbone.Collection.extend({
72 model: a2.TabModel
73 }), a2.CategoryModel = Backbone.Model.extend({
74 defaults: {
75 slug: "",
76 title: ""
77 }
78 }), a2.KeywordsModel = Backbone.Model.extend({
79 defaults: {
80 keywords: {}
81 }
82 }), a2.CategoriesCollection = Backbone.Collection.extend({
83 model: a2.CategoryModel
84 }), a2.KeywordsView = Marionette.ItemView.extend({
85 id: "elementor-template-library-filter",
86 template: "#views-ma-el-template-modal-keywords",
87 onRender: function() {
88 var self = this;
89 setTimeout(function() {
90 jQuery(".ma-el-keywords-filter-action").off("click").on("click", function(e2) {
91 e2.preventDefault();
92 e2.stopPropagation();
93 jQuery(".ma-el-keywords-filters-container").toggleClass("active");
94 });
95 jQuery(".ma-el-keywords-filter-item").off("click").on("click", function(e2) {
96 e2.preventDefault();
97 var keywordValue = jQuery(this).data("keyword");
98 var keywordTitle = jQuery(this).text();
99 t.setFilter("keyword", keywordValue);
100 jQuery("#ma-el-keywords-selected-filter").text(keywordTitle);
101 jQuery(".ma-el-keywords-filters-container").removeClass("active");
102 });
103 jQuery(document).off("click.keywordsDropdown").on("click.keywordsDropdown", function(e2) {
104 if (!jQuery(e2.target).closest(".ma-el-keywords-filters-wrap").length) {
105 jQuery(".ma-el-keywords-filters-container").removeClass("active");
106 }
107 });
108 }, 100);
109 }
110 }), a2.ModalPreviewView = Marionette.ItemView.extend({
111 template: "#views-ma-el-template-modal-preview",
112 id: "ma-el-item-preview-wrap",
113 ui: {
114 iframe: "iframe",
115 notice: ".ma-el-item-notice"
116 },
117 onRender: function() {
118 if (null !== this.getOption("notice") && this.getOption("notice").length) {
119 var e2 = "";
120 -1 !== this.getOption("notice").indexOf("facebook") ? e2 += "<p>Please login with your Facebook account in order to get your Facebook Reviews.</p>" : -1 !== this.getOption("notice").indexOf("google") ? e2 += "<p>You need to add your Google API key from Dashboard -> Master Addons for Elementor -> Google Maps</p>" : -1 !== this.getOption("notice").indexOf("form") && (e2 += "<p>You need to have <a href='https://wordpress.org/plugins/contact-form-7/' target='_blank'>Contact Form 7 plugin</a> installed and active.</p>"), this.ui.notice.html("<div><p><strong>Important!</strong></p>" + e2 + "</div>");
121 }
122 this.ui.iframe.attr("src", this.getOption("url"));
123 }
124 }), a2.ModalHeaderBack = Marionette.ItemView.extend({
125 template: "#views-ma-el-template-modal-header-back",
126 id: "ma-el-template-modal-header-back",
127 ui: {
128 button: "button"
129 },
130 events: {
131 "click @ui.button": "onBackClick"
132 },
133 onBackClick: function() {
134 t.setPreview("back");
135 }
136 }), a2.ModalHeaderLogo = Marionette.ItemView.extend({
137 template: "#views-ma-el-template-modal-header-logo",
138 id: "ma-el-template-modal-header-logo"
139 }), a2.ModalBodyView = Marionette.LayoutView.extend({
140 template: "#views-ma-el-template-modal-content",
141 id: "ma-el-template-library-content",
142 className: function() {
143 return "library-tab-" + t.getTab();
144 },
145 regions: {
146 contentTemplates: ".ma-el-templates-list",
147 contentFilters: ".ma-el-filters-list",
148 contentKeywords: ".ma-el-keywords-list"
149 },
150 onRender: function() {
151 var self = this;
152 setTimeout(function() {
153 jQuery("#ma-el-template-search-input").off("input").on("input", function() {
154 var searchTerm = jQuery(this).val().toLowerCase();
155 t.setFilter("search", searchTerm);
156 });
157 }, 100);
158 }
159 }), a2.LibraryLoadingView = Marionette.ItemView.extend({
160 id: "ma-el-modal-template-library-loading",
161 template: "#views-ma-el-template-modal-loading"
162 }), a2.LibraryErrorView = Marionette.ItemView.extend({
163 id: "ma-el-modal-template-error",
164 template: "#views-ma-el-template-modal-error"
165 }), a2.ModalInsertTemplateBehavior = Marionette.Behavior.extend({
166 ui: {
167 insertButton: ".ma-el-template-insert"
168 },
169 events: {
170 "click @ui.insertButton": "onInsertButtonClick"
171 },
172 onInsertButtonClick: function() {
173 var a3 = this.view.model, o2 = a3.attributes.dependencies, n2 = a3.attributes.pro, l = Object.keys(o2).length, r = {};
174 if (t.layout.showLoadingView(), 0 < l)
175 for (var s in o2) e.ajax({
176 url: ajaxurl,
177 type: "post",
178 dataType: "json",
179 data: {
180 action: "jltma_inner_template",
181 security: MasterAddonsData.insert_template_nonce,
182 template: o2[s],
183 tab: t.getTab()
184 }
185 });
186 "valid" !== i.license.status && n2 ? t.layout.showLicenseError() : elementor.templates.requestTemplateContent(a3.get("source"), a3.get("template_id"), {
187 data: {
188 tab: t.getTab(),
189 page_settings: false
190 },
191 success: function(e2) {
192 e2.license ? (console.log("%c !", "color: #7a7a7a; background-color: #eee;"), t.closeModal(), elementor.channels.data.trigger("$e.run( 'document/import' )", a3), null !== t.atIndex && (r.at = t.atIndex), elementor.config.version < "3.0.0" ? elementor.sections.currentView.addChildModel(e2.content, r) : elementor.previewView.addChildModel(e2.content, r), elementor.channels.data.trigger("template:after:insert", a3), t.atIndex = null) : t.layout.showLicenseError();
193 jQuery("body").removeClass("elementor-editor-preview").addClass("elementor-editor-active");
194 },
195 error: function(e2) {
196 console.log(e2);
197 }
198 });
199 }
200 }), a2.ModalHeaderInsertButton = Marionette.ItemView.extend({
201 template: "#views-ma-el-template-modal-insert-button",
202 id: "jltma-template-modal-insert-wrapper",
203 className: "elementor-template-library-template-action jltma-modal-template-header-item",
204 behaviors: {
205 insertTemplate: {
206 behaviorClass: a2.ModalInsertTemplateBehavior
207 }
208 }
209 }), a2.MasterProButton = Marionette.ItemView.extend({
210 template: "#views-ma-el-template-pro-button",
211 id: "ma-el-modal-template-pro-button"
212 }), a2.ModalTemplateItemView = Marionette.ItemView.extend({
213 template: "#views-ma-el-template-modal-item",
214 className: function() {
215 var e2 = " ma-el-modal-template-has-url", t2 = "";
216 return "" === this.model.get("preview") && (e2 = " ma-el-modal-template-no-url"), this.model.get("pro") && "valid" != i.license.status && (t2 = " ma-el-modal-template-pro"), "elementor-template-library-template elementor-template-library-template-remote" + e2 + t2;
217 },
218 ui: function() {
219 return {
220 previewButton: ".elementor-template-library-template-preview"
221 };
222 },
223 events: function() {
224 return {
225 "click @ui.previewButton": "onPreviewButtonClick"
226 };
227 },
228 onPreviewButtonClick: function() {
229 "" !== this.model.get("url") && t.setPreview(this.model);
230 },
231 behaviors: {
232 insertTemplate: {
233 behaviorClass: a2.ModalInsertTemplateBehavior
234 }
235 }
236 }), a2.FiltersItemView = Marionette.ItemView.extend({
237 template: "#views-ma-el-template-modal-filters-item",
238 tagName: "li",
239 className: "ma-el-modal-template-filter-item",
240 attributes: function() {
241 return {
242 "data-filter": this.model.get("slug")
243 };
244 },
245 events: function() {
246 return {
247 "click": "onFilterClick"
248 };
249 },
250 onFilterClick: function(e2) {
251 var filterValue = this.model.get("slug");
252 var filterTitle = this.model.get("title");
253 jQuery(".ma-el-library-keywords").val(""), t.setFilter("category", filterValue), t.setFilter("keyword", "");
254 jQuery("#ma-el-modal-selected-filter").text(filterTitle);
255 jQuery(".ma-el-modal-filters-container").removeClass("active");
256 }
257 }), a2.ModalTabsItemView = Marionette.ItemView.extend({
258 template: "#views-ma-el-template-modal-tabs-item",
259 className: function() {
260 return "elementor-template-library-menu-item";
261 },
262 ui: function() {
263 return {
264 tabsLabels: "label",
265 tabsInput: "input"
266 };
267 },
268 events: function() {
269 return {
270 "click @ui.tabsLabels": "onTabClick"
271 };
272 },
273 onRender: function() {
274 this.model.get("slug") === t.getTab() && this.ui.tabsInput.attr("checked", "checked");
275 },
276 onTabClick: function(e2) {
277 var a3 = jQuery(e2.target);
278 t.setTab(a3.val()), t.setFilter("keyword", "");
279 }
280 }), a2.FiltersCollectionView = Marionette.CompositeView.extend({
281 id: "ma-el-modal-template-library-filters",
282 template: "#views-ma-el-template-modal-filters",
283 childViewContainer: "#ma-el-modal-filters-container ul",
284 getChildView: function(e2) {
285 return a2.FiltersItemView;
286 },
287 onRender: function() {
288 var self = this;
289 setTimeout(function() {
290 jQuery(".ma-el-modal-filter-action").off("click").on("click", function(e2) {
291 e2.preventDefault();
292 e2.stopPropagation();
293 jQuery(".ma-el-modal-filters-container").toggleClass("active");
294 });
295 jQuery(document).off("click.filterDropdown").on("click.filterDropdown", function(e2) {
296 if (!jQuery(e2.target).closest(".ma-el-modal-filters-wrap").length) {
297 jQuery(".ma-el-modal-filters-container").removeClass("active");
298 }
299 });
300 }, 100);
301 }
302 }), a2.ModalTabsCollectionView = Marionette.CompositeView.extend({
303 template: "#views-ma-el-template-modal-tabs",
304 childViewContainer: "#views-ma-el-template-modal-tabs-items",
305 initialize: function() {
306 this.listenTo(t.channels.layout, "tamplate:cloned", this._renderChildren);
307 },
308 getChildView: function(e2) {
309 return a2.ModalTabsItemView;
310 }
311 }), a2.ModalCollectionView = Marionette.CompositeView.extend({
312 template: "#views-ma-el-template-modal-templates",
313 id: "ma-el-modal-template-library-templates",
314 childViewContainer: "#ma-el-modal-templates-container",
315 initialize: function() {
316 this.listenTo(t.channels.templates, "filter:change", this._renderChildren);
317 },
318 filter: function(e2) {
319 var a3 = t.getFilter("category"), o2 = t.getFilter("keyword"), s = t.getFilter("search");
320 var matchesFilters = !a3 && !o2 || (o2 && !a3 ? _.contains(e2.get("keywords"), o2) : a3 && !o2 ? _.contains(e2.get("categories"), a3) : _.contains(e2.get("categories"), a3) && _.contains(e2.get("keywords"), o2));
321 if (s && s.length > 0) {
322 var title = (e2.get("title") || e2.get("name") || "").toLowerCase();
323 var matchesSearch = title.indexOf(s) !== -1;
324 return matchesFilters && matchesSearch;
325 }
326 return matchesFilters;
327 },
328 getChildView: function(e2) {
329 return a2.ModalTemplateItemView;
330 },
331 onRenderCollection: function() {
332 var self = this;
333 var e2 = this.$childViewContainer, n2 = t.getTab();
334 console.log("Skipping Marionette masonry initialization - Macy handles layout");
335 return;
336 }
337 }), a2.ModalLoadingView = Marionette.ItemView.extend({
338 id: "ma-el-modal-loading",
339 template: "#views-ma-el-template-modal-loading"
340 }), a2.ModalErrorView = Marionette.ItemView.extend({
341 id: "ma-el-modal-loading",
342 template: "#views-ma-el-template-modal-error"
343 }), a2.ModalLayoutView = Marionette.LayoutView.extend({
344 el: "#ma-el-modal-template",
345 regions: i.modalRegions,
346 initialize: function() {
347 this.getRegion("modalHeader").show(new a2.ModalHeaderView()), this.listenTo(t.channels.tabs, "filter:change", this.switchTabs), this.listenTo(t.channels.layout, "preview:change", this.switchPreview);
348 },
349 switchTabs: function() {
350 this.showLoadingView(), t.setFilter("keyword", ""), t.requestTemplates(t.getTab());
351 },
352 switchPreview: function() {
353 var e2 = this.getHeaderView(), o2 = t.getPreview(), n2 = t.getFilter("category"), i2 = t.getFilter("keyword");
354 return "back" === o2 ? (e2.headerLogo.show(new a2.ModalHeaderLogo()), e2.headerTabs.show(new a2.ModalTabsCollectionView({
355 collection: t.collections.tabs
356 })), e2.headerActions.empty(), t.setTab(t.getTab()), "" != n2 && (t.setFilter("category", n2), jQuery("#ma-el-modal-filters-container").find("input[value='" + n2 + "']").prop("checked", true)), void ("" != i2 && t.setFilter("keyword", i2))) : "initial" === o2 ? (e2.headerActions.empty(), void e2.headerLogo.show(new a2.ModalHeaderLogo())) : (this.getRegion("modalContent").show(new a2.ModalPreviewView({
357 preview: o2.get("preview"),
358 url: o2.get("url"),
359 notice: o2.get("notice")
360 })), e2.headerLogo.empty(), e2.headerTabs.show(new a2.ModalHeaderBack()), void e2.headerActions.show(new a2.ModalHeaderInsertButton({
361 model: o2
362 })));
363 },
364 getHeaderView: function() {
365 return this.getRegion("modalHeader").currentView;
366 },
367 getContentView: function() {
368 return this.getRegion("modalContent").currentView;
369 },
370 showLoadingView: function() {
371 this.modalContent.show(new a2.ModalLoadingView());
372 },
373 showLicenseError: function() {
374 this.modalContent.show(new a2.ModalErrorView());
375 },
376 showTemplatesView: function(e2, o2, n2) {
377 this.getRegion("modalContent").show(new a2.ModalBodyView());
378 var i2 = this.getContentView(), l = this.getHeaderView(), r = new a2.KeywordsModel({
379 keywords: n2
380 });
381 t.collections.tabs = new a2.ModalTabsCollection(t.getTabs()), l.headerTabs.show(new a2.ModalTabsCollectionView({
382 collection: t.collections.tabs
383 })), i2.contentTemplates.show(new a2.ModalCollectionView({
384 collection: e2
385 })), i2.contentFilters.show(new a2.FiltersCollectionView({
386 collection: o2
387 })), i2.contentKeywords.show(new a2.KeywordsView({
388 model: r
389 }));
390 }
391 });
392 },
393 masonry: {
394 instance: null,
395 init: function(t2) {
396 console.log("Marionette masonry.init() called but disabled - Macy from assets.php handles layout");
397 return;
398 },
399 fallbackMasonry: function(t2) {
400 console.log("Hello");
401 var self = this;
402 self.settings = e.extend(self.getDefaultSettings(), t2);
403 self.elements = self.getDefaultElements();
404 self.runFallback();
405 },
406 getDefaultSettings: function() {
407 return {
408 container: null,
409 items: null,
410 columnsCount: 3,
411 verticalSpaceBetween: 30
412 };
413 },
414 getDefaultElements: function() {
415 return {
416 $container: jQuery(this.settings.container),
417 $items: jQuery(this.settings.items)
418 };
419 },
420 runFallback: function() {
421 var e2 = [], t2 = this.elements.$container.position().top, a2 = this.settings, o2 = a2.columnsCount;
422 t2 += parseInt(this.elements.$container.css("margin-top"), 10);
423 this.elements.$container.height("");
424 this.elements.$items.each(function(n2) {
425 var i2 = Math.floor(n2 / o2), l = n2 % o2, r = jQuery(this), s = r.position(), d = r[0].getBoundingClientRect().height + a2.verticalSpaceBetween;
426 if (i2) {
427 var m = s.top - t2 - e2[l];
428 m -= parseInt(r.css("margin-top"), 10);
429 m *= -1;
430 r.css("margin-top", m + "px");
431 e2[l] += d;
432 } else {
433 e2.push(d);
434 }
435 });
436 this.elements.$container.height(Math.max.apply(Math, e2));
437 }
438 }
439 }, t = {
440 modal: !(n = {
441 getDataToSave: function(e2) {
442 return e2.id = window.elementor.config.post_id, e2;
443 },
444 init: function() {
445 window.elementor.settings.master_template && (window.elementor.settings.master_template.getDataToSave = this.getDataToSave), window.elementor.settings.master_page && (window.elementor.settings.master_page.getDataToSave = this.getDataToSave, window.elementor.settings.master_page.changeCallbacks = {
446 custom_header: function() {
447 this.save(function() {
448 elementor.reloadPreview(), elementor.once("preview:loaded", function() {
449 elementor.getPanelView().setPage("master_page_settings");
450 });
451 });
452 },
453 custom_footer: function() {
454 this.save(function() {
455 elementor.reloadPreview(), elementor.once("preview:loaded", function() {
456 elementor.getPanelView().setPage("master_page_settings");
457 });
458 });
459 }
460 });
461 }
462 }),
463 layout: !(o = {
464 MasterSearchView: null,
465 init: function() {
466 this.MasterSearchView = window.elementor.modules.controls.BaseData.extend({
467 onReady: function() {
468 var t2 = this.model.attributes.action, a2 = this.model.attributes.query_params;
469 this.ui.select.find("option").each(function(t3, a3) {
470 e(this).attr("selected", true);
471 }), this.ui.select.select2({
472 ajax: {
473 url: function() {
474 var o2 = "";
475 return 0 < a2.length && e.each(a2, function(e2, t3) {
476 window.elementor.settings.page.model.attributes[t3] && (o2 += "&" + t3 + "=" + window.elementor.settings.page.model.attributes[t3]);
477 }), ajaxurl + "?action=" + t2 + o2;
478 },
479 dataType: "json"
480 },
481 placeholder: "Please enter 3 or more characters",
482 minimumInputLength: 3
483 });
484 },
485 onBeforeDestroy: function() {
486 this.ui.select.data("select2") && this.ui.select.select2("destroy"), this.$el.remove();
487 }
488 }), window.elementor.addControlView("master_search", this.MasterSearchView);
489 }
490 }),
491 collections: {},
492 tabs: {},
493 defaultTab: "",
494 channels: {},
495 atIndex: null,
496 init: function() {
497 window.elementor.on("preview:loaded", window._.bind(t.onPreviewLoaded, t)), a.init(), o.init(), n.init();
498 },
499 onPreviewLoaded: function() {
500 let e2 = setInterval(() => {
501 window.elementor.$previewContents.find(".elementor-add-new-section").length && (this.initMasterTempsButton(), clearInterval(e2));
502 }, 100);
503 window.elementor.$previewContents.on("click.addMasterTemplate", ".ma-el-add-section-btn", _.bind(function() {
504 this.toggleEditorMode();
505 this.showTemplatesModal();
506 }, this)), this.channels = {
507 templates: Backbone.Radio.channel("MASTER_EDITOR:templates"),
508 tabs: Backbone.Radio.channel("MASTER_EDITOR:tabs"),
509 layout: Backbone.Radio.channel("MASTER_EDITOR:layout")
510 }, this.tabs = i.tabs, this.defaultTab = i.defaultTab;
511 },
512 initMasterTempsButton: function() {
513 var a2 = window.elementor.$previewContents.find(".elementor-add-new-section"), o2 = '<button type="button" class="elementor-add-section-area-button ma-el-add-section-btn" title="Master Addons Templates" aria-label="Master Addons Templates"><div class="jltma-editor-icon"></div></button>';
514 a2.length && i.MasterAddonsEditorBtn && a2.each(function() {
515 var $section = e(this);
516 if (!$section.find(".ma-el-add-section-btn").length) {
517 var $dragTitle = $section.find(".elementor-add-section-drag-title");
518 if ($dragTitle.length) {
519 e(o2).insertBefore($dragTitle);
520 } else {
521 $section.append(e(o2));
522 }
523 }
524 });
525 window.elementor.$previewContents.on("click.addMasterTemplate", ".elementor-editor-section-settings .elementor-editor-element-add", function() {
526 t.toggleEditorMode();
527 var a3 = e(this).closest(".elementor-top-section"), n2 = a3.data("model-cid");
528 elementor.config.version < "3.0.0" ? window.elementor.sections.currentView.collection.length && e.each(window.elementor.sections.currentView.collection.models, function(e2, a4) {
529 n2 === a4.cid && (t.atIndex = e2);
530 }) : elementor.previewView.collection.length && e.each(elementor.previewView.collection.models, function(e2, a4) {
531 n2 === a4.cid && (t.atIndex = e2);
532 });
533 if (i.MasterAddonsEditorBtn) {
534 var $addSection = a3.prev(".elementor-add-section").find(".elementor-add-new-section");
535 if (!$addSection.find(".ma-el-add-section-btn").length) {
536 var $dragTitle = $addSection.find(".elementor-add-section-drag-title");
537 if ($dragTitle.length) {
538 e(o2).insertBefore($dragTitle);
539 } else {
540 $addSection.append(e(o2));
541 }
542 }
543 }
544 });
545 },
546 getFilter: function(e2) {
547 return this.channels.templates.request("filter:" + e2);
548 },
549 setFilter: function(e2, t2) {
550 this.channels.templates.reply("filter:" + e2, t2), this.channels.templates.trigger("filter:change");
551 },
552 getTab: function() {
553 return this.channels.tabs.request("filter:tabs");
554 },
555 setTab: function(e2, t2) {
556 this.channels.tabs.reply("filter:tabs", e2), t2 || this.channels.tabs.trigger("filter:change");
557 },
558 getTabs: function() {
559 var e2 = [];
560 return _.each(this.tabs, function(t2, a2) {
561 e2.push({
562 slug: a2,
563 title: t2.title
564 });
565 }), e2;
566 },
567 getPreview: function(e2) {
568 return this.channels.layout.request("preview");
569 },
570 setPreview: function(e2, t2) {
571 this.channels.layout.reply("preview", e2), t2 || this.channels.layout.trigger("preview:change");
572 },
573 getKeywords: function() {
574 return _.each(this.keywords, function(e2, t2) {
575 tabs.push({
576 slug: t2,
577 title: e2
578 });
579 }), [];
580 },
581 showTemplatesModal: function() {
582 jQuery("body").addClass("master-addons-template-popup-loaded");
583 var modal = this.getModal();
584 modal.show();
585 setTimeout(function() {
586 e(".dialog-widget-content").off("click");
587 e(".dialog-lightbox-widget").off("click");
588 e(".dialog-lightbox-widget-content").off("click");
589 e(".dialog-widget-content, .dialog-lightbox-widget").on("click", function(event) {
590 if (event.target === this) {
591 event.stopPropagation();
592 event.preventDefault();
593 return false;
594 }
595 });
596 }, 100);
597 this.layout || (this.layout = new a.ModalLayoutView(), this.layout.showLoadingView()), this.setTab(this.defaultTab, true), this.requestTemplates(this.defaultTab), this.setPreview("initial");
598 },
599 requestTemplates: function(t2) {
600 var o2 = this, n2 = o2.tabs[t2];
601 o2.setFilter("category", false), n2.data.templates && n2.data.categories ? o2.layout.showTemplatesView(n2.data.templates, n2.data.categories, n2.data.keywords) : e.ajax({
602 url: ajaxurl,
603 type: "get",
604 dataType: "json",
605 data: {
606 action: "jltma_get_templates",
607 security: MasterAddonsData.get_templates_nonce,
608 tab: t2,
609 page: 1
610 },
611 success: function(e2) {
612 var n3 = new a.LibraryCollection(e2.data.templates), i2 = new a.CategoriesCollection(e2.data.categories);
613 o2.tabs[t2].data = {
614 templates: n3,
615 categories: i2,
616 keywords: e2.data.keywords,
617 pagination: e2.data.pagination || null
618 }, o2.layout.showTemplatesView(n3, i2, e2.data.keywords);
619 }
620 });
621 },
622 loadMoreTemplates: function() {
623 var o2 = this, tab = o2.getTab(), tabData = o2.tabs[tab].data;
624 if (!tabData || !tabData.pagination || !tabData.pagination.has_more || o2._loadingMore) return;
625 o2._loadingMore = true;
626 var nextPage = tabData.pagination.current_page + 1;
627 var $loading = e(".ma-el-template-loading-more");
628 if ($loading.length) $loading.show();
629 e.ajax({
630 url: ajaxurl,
631 type: "get",
632 dataType: "json",
633 data: {
634 action: "jltma_get_templates",
635 security: MasterAddonsData.get_templates_nonce,
636 tab,
637 page: nextPage
638 },
639 success: function(response) {
640 if (response.data && response.data.templates && response.data.templates.length > 0) {
641 tabData.templates.add(response.data.templates);
642 tabData.pagination = response.data.pagination;
643 }
644 o2._loadingMore = false;
645 if ($loading.length) $loading.hide();
646 },
647 error: function() {
648 o2._loadingMore = false;
649 if ($loading.length) $loading.hide();
650 }
651 });
652 },
653 closeModal: function() {
654 this.getModal().hide();
655 jQuery("body").removeClass("master-addons-template-popup-loaded");
656 },
657 getModal: function() {
658 return this.modal || (this.modal = elementor.dialogsManager.createWidget("lightbox", {
659 id: "ma-el-modal-template",
660 className: "elementor-templates-modal",
661 closeButton: false,
662 closeOnOutsideClick: false,
663 closeOnEscKey: false,
664 hide: {
665 onOutsideClick: false,
666 onEscKeyPress: false
667 }
668 })), this.modal;
669 },
670 editorCheck: function() {
671 return e("body").hasClass("elementor-editor-active") ? true : false;
672 },
673 toggleEditorMode: function() {
674 var body = e("body");
675 body.removeClass("elementor-editor-active").addClass("elementor-editor-preview");
676 body.removeClass("master-addons-template-popup-loaded");
677 }
678 }, e(window).on("elementor:init", t.init);
679 window.MasterAddonsEditor = t;
680 e(document).on("click", "#ma-el-template-cache-refresh", function(event) {
681 event.preventDefault();
682 var $button = e(this);
683 var $icon = $button.find("i");
684 $button.addClass("updating");
685 $icon.removeClass("eicon-sync").addClass("eicon-loading eicon-animation-spin");
686 e.ajax({
687 type: "POST",
688 url: ajaxurl,
689 data: {
690 action: "jltma_refresh_templates_cache",
691 _wpnonce: MasterAddonsData.refresh_cache_nonce
692 },
693 success: function(response) {
694 if (response.success) {
695 console.log("Template cache refreshed successfully");
696 var $cacheStatus = e("#ma-el-template-cache-status");
697 if ($cacheStatus.length && response.data.total_templates) {
698 var newCount = response.data.total_templates;
699 $cacheStatus.find(".cache-count").text(newCount);
700 $cacheStatus.attr("title", "Cache Status: " + newCount + " templates cached");
701 if (newCount > 0) {
702 $cacheStatus.show();
703 } else {
704 $cacheStatus.hide();
705 }
706 }
707 $button.removeClass("updating");
708 $icon.removeClass("eicon-loading eicon-animation-spin").addClass("eicon-sync");
709 setTimeout(function() {
710 if (t && t.getTab) {
711 var currentTab = t.getTab();
712 if (t.tabs && t.tabs[currentTab]) {
713 t.tabs[currentTab].data = null;
714 }
715 t.requestTemplates(currentTab);
716 }
717 }, 500);
718 $button.attr("title", "Cache refreshed successfully!");
719 setTimeout(function() {
720 $button.attr("title", "Refresh Cache");
721 }, 3e3);
722 } else {
723 console.error("Failed to refresh template cache:", response.data ? response.data.message : "Unknown error");
724 $button.removeClass("updating");
725 $icon.removeClass("eicon-loading eicon-animation-spin").addClass("eicon-sync");
726 }
727 },
728 error: function(xhr, status, error) {
729 console.error("AJAX error refreshing template cache:", error);
730 $button.removeClass("updating");
731 $icon.removeClass("eicon-loading eicon-animation-spin").addClass("eicon-sync");
732 }
733 });
734 });
735 })(jQuery);
736 })();
737