PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.2.3
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.2.3
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.2.3, at assets/js/admin/editor.js

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