File: //proc/self/cwd/wp-content/plugins/happy-elementor-addons/assets/admin/js/template-library.min.js
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}!function(p,u,n){var h={Views:{},Models:{},Collections:{},Behaviors:{},Layout:null,Manager:null};h.Models.Template=Backbone.Model.extend({defaults:{template_id:0,title:"",type:"",thumbnail:"",url:"",tags:[],isPro:!1}}),h.Collections.Template=Backbone.Collection.extend({model:h.Models.Template}),h.Behaviors.InsertTemplate=Marionette.Behavior.extend({ui:{insertButton:".haTemplateLibrary__insert-button"},events:{"click @ui.insertButton":"onInsertButtonClick"},onInsertButtonClick:function(){n.library.insertTemplate({model:this.view.model})}}),h.Views.EmptyTemplateCollection=Marionette.ItemView.extend({id:"elementor-template-library-templates-empty",template:"#tmpl-haTemplateLibrary__empty",ui:{title:".elementor-template-library-blank-title",message:".elementor-template-library-blank-message"},modesStrings:{empty:{title:haGetTranslated("templatesEmptyTitle"),message:haGetTranslated("templatesEmptyMessage")},noResults:{title:haGetTranslated("templatesNoResultsTitle"),message:haGetTranslated("templatesNoResultsMessage")}},getCurrentMode:function(){return n.library.getFilter("text")?"noResults":"empty"},onRender:function(){var e=this.modesStrings[this.getCurrentMode()];this.ui.title.html(e.title),this.ui.message.html(e.message)}}),h.Views.Loading=Marionette.ItemView.extend({template:"#tmpl-haTemplateLibrary__loading",id:"haTemplateLibrary__loading"}),h.Views.Logo=Marionette.ItemView.extend({template:"#tmpl-haTemplateLibrary__header-logo",className:"haTemplateLibrary__header-logo",templateHelpers:function(){return{title:this.getOption("title")}}}),h.Views.BackButton=Marionette.ItemView.extend({template:"#tmpl-haTemplateLibrary__header-back",id:"elementor-template-library-header-preview-back",className:"haTemplateLibrary__header-back",events:function(){return{click:"onClick"}},onClick:function(){n.library.showTemplatesView()}}),h.Views.Menu=Marionette.ItemView.extend({template:"#tmpl-haTemplateLibrary__header-menu",id:"elementor-template-library-header-menu",className:"haTemplateLibrary__header-menu",templateHelpers:function(){return n.library.getTabs()},ui:{menuItem:".elementor-template-library-menu-item"},events:{"click @ui.menuItem":"onMenuItemClick"},onMenuItemClick:function(e){n.library.setFilter("tags",""),n.library.setFilter("text",""),n.library.setFilter("type",e.currentTarget.dataset.tab,!0),n.library.showTemplatesView()}}),h.Views.ResponsiveMenu=Marionette.ItemView.extend({template:"#tmpl-haTemplateLibrary__header-menu-responsive",id:"elementor-template-library-header-menu-responsive",className:"haTemplateLibrary__header-menu-responsive",ui:{items:"> .elementor-component-tab"},events:{"click @ui.items":"onTabItemClick"},onTabItemClick:function(e){var e=p(e.currentTarget),t=e.data("tab");n.library.channels.tabs.trigger("change:device",t,e)}}),h.Views.Actions=Marionette.ItemView.extend({template:"#tmpl-haTemplateLibrary__header-actions",id:"elementor-template-library-header-actions",ui:{sync:"#haTemplateLibrary__header-sync i"},events:{"click @ui.sync":"onSyncClick"},onSyncClick:function(){var e=this;e.ui.sync.addClass("eicon-animation-spin"),n.library.requestLibraryData({onUpdate:function(){e.ui.sync.removeClass("eicon-animation-spin"),n.library.updateBlocksView()},forceUpdate:!0,forceSync:!0})}}),h.Views.InsertWrapper=Marionette.ItemView.extend({template:"#tmpl-haTemplateLibrary__header-insert",id:"elementor-template-library-header-preview",behaviors:{insertTemplate:{behaviorClass:h.Behaviors.InsertTemplate}}}),h.Views.Preview=Marionette.ItemView.extend({template:"#tmpl-haTemplateLibrary__preview",className:"haTemplateLibrary__preview",ui:function(){return{iframe:"> iframe"}},onRender:function(){this.ui.iframe.attr("src",this.getOption("url")).hide();var e=this,t=(new h.Views.Loading).render();this.$el.append(t.el),this.ui.iframe.on("load",function(){e.$el.find("#haTemplateLibrary__loading").remove(),e.ui.iframe.show()})}}),h.Views.TemplateCollection=Marionette.CompositeView.extend({template:"#tmpl-haTemplateLibrary__templates",id:"haTemplateLibrary__templates",className:function(){return"haTemplateLibrary__templates haTemplateLibrary__templates--"+n.library.getFilter("type")},childViewContainer:"#haTemplateLibrary__templates-list",emptyView:function(){return new h.Views.EmptyTemplateCollection},ui:{templatesWindow:".haTemplateLibrary__templates-window",textFilter:"#haTemplateLibrary__search",tagsFilter:"#haTemplateLibrary__filter-tags",filterBar:"#haTemplateLibrary__toolbar-filter",counter:"#haTemplateLibrary__toolbar-counter"},events:{"input @ui.textFilter":"onTextFilterInput","click @ui.tagsFilter li":"onTagsFilterClick"},getChildView:function(e){return h.Views.Template},initialize:function(){this.listenTo(n.library.channels.templates,"filter:change",this._renderChildren)},filter:function(i){var e=n.library.getFilterTerms(),a=!0;return _.each(e,function(e,t){t=n.library.getFilter(t);return t&&e.callback?((e=e.callback.call(i,t))||(a=!1),e):void 0}),a},setMasonrySkin:function(){var e;"section"===n.library.getFilter("type")&&(e=new elementorModules.utils.Masonry({container:this.$childViewContainer,items:this.$childViewContainer.children()}),this.$childViewContainer.imagesLoaded(e.run.bind(e)))},onRenderCollection:function(){this.setMasonrySkin(),this.updatePerfectScrollbar(),this.setTemplatesFoundText()},setTemplatesFoundText:function(){var e=n.library.getFilter("type"),t=this.children.length,i="<b>"+t+"</b>";i+="section"===e?" block":" "+e,1<t&&(i+="s"),this.ui.counter.html(i+=" found")},onTextFilterInput:function(){var e=this;_.defer(function(){n.library.setFilter("text",e.ui.textFilter.val())})},onTagsFilterClick:function(e){var e=p(e.currentTarget),t=e.data("tag");n.library.setFilter("tags",t),e.addClass("active").siblings().removeClass("active"),t=t?n.library.getTags()[t]:"Filter",this.ui.filterBar.find(".haTemplateLibrary__filter-btn").html(t+' <i class="eicon-caret-down"></i>')},updatePerfectScrollbar:function(){this.perfectScrollbar||(this.perfectScrollbar=new PerfectScrollbar(this.ui.templatesWindow[0],{suppressScrollX:!0})),this.perfectScrollbar.isRtl=!1,this.perfectScrollbar.update()},setTagsFilterHover:function(){var e=this;e.ui.filterBar.hoverIntent(function(){e.ui.tagsFilter.css("display","block"),e.ui.filterBar.find(".haTemplateLibrary__filter-btn i").addClass("eicon-caret-down").removeClass("eicon-caret-right")},function(){e.ui.tagsFilter.css("display","none"),e.ui.filterBar.find(".haTemplateLibrary__filter-btn i").addClass("eicon-caret-right").removeClass("eicon-caret-down")},{sensitivity:50,interval:150,timeout:100})},onRender:function(){this.setTagsFilterHover(),this.updatePerfectScrollbar()}}),h.Views.Template=Marionette.ItemView.extend({template:"#tmpl-haTemplateLibrary__template",className:"haTemplateLibrary__template",ui:{previewButton:".haTemplateLibrary__preview-button, .haTemplateLibrary__template-preview"},events:{"click @ui.previewButton":"onPreviewButtonClick"},behaviors:{insertTemplate:{behaviorClass:h.Behaviors.InsertTemplate}},onPreviewButtonClick:function(){n.library.showPreviewView(this.model)}}),h.Modal=elementorModules.common.views.modal.Layout.extend({getModalOptions:function(){return{id:"haTemplateLibrary__modal",hide:{onOutsideClick:!1,onEscKeyPress:!0,onBackgroundClick:!1}}},getTemplateActionButton:function(e){e=e.isPro&&!HappyAddonsEditor.hasPro?"pro-button":"insert-button",e=Marionette.TemplateCache.get("#tmpl-haTemplateLibrary__"+e);return Marionette.Renderer.render(e)},showLogo:function(e){this.getHeaderView().logoArea.show(new h.Views.Logo(e))},showDefaultHeader:function(){this.showLogo({title:"TEMPLATES"});var e=this.getHeaderView();e.tools.show(new h.Views.Actions),e.menuArea.show(new h.Views.Menu)},showPreviewView:function(e){var t=this.getHeaderView();t.menuArea.show(new h.Views.ResponsiveMenu),t.logoArea.show(new h.Views.BackButton),t.tools.show(new h.Views.InsertWrapper({model:e})),this.modalContent.show(new h.Views.Preview({url:e.get("url")}))},showTemplatesView:function(e){this.showDefaultHeader(),this.modalContent.show(new h.Views.TemplateCollection({collection:e}))}}),h.Manager=function(){var e,i,a,n,t,r=this,o=".elementor-add-new-section .elementor-add-section-drag-title",l='<div class="elementor-add-section-area-button elementor-add-ha-button"> <i class="hm hm-happyaddons"></i> </div>',s={desktop:"100%",tab:"768px",mobile:"360px"};function c(){var e=p(this).closest(".elementor-top-section"),i=e.data("id"),t=u.documents.getCurrent().container.children,e=e.prev(".elementor-add-section");t&&_.each(t,function(e,t){i===e.id&&(r.atIndex=t)}),e.find(".elementor-add-ha-button").length||e.find(o).before(l)}function m(e,t){t.addClass("elementor-active").siblings().removeClass("elementor-active");t=s[e]||s.desktop;p(".haTemplateLibrary__preview").css("width",t)}function d(){var i=window.elementor.$previewContents,a=setInterval(function(){var e,t;(t=(e=i).find(o)).length&&!e.find(".elementor-add-ha-button").length&&t.before(l),e.on("click.onAddElement",".elementor-editor-section-settings .elementor-editor-element-add",c),0<i.find(".elementor-add-new-section").length&&clearInterval(a)},100);i.on("click.onAddTemplateButton",".elementor-add-ha-button",r.showModal.bind(r)),this.channels.tabs.on("change:device",m)}this.atIndex=-1,this.channels={tabs:Backbone.Radio.channel("tabs"),templates:Backbone.Radio.channel("templates")},this.updateBlocksView=function(){r.setFilter("tags","",!0),r.setFilter("text","",!0),r.getModal().showTemplatesView(n)},this.setFilter=function(e,t,i){r.channels.templates.reply("filter:"+e,t),i||r.channels.templates.trigger("filter:change")},this.getFilter=function(e){return r.channels.templates.request("filter:"+e)},this.getFilterTerms=function(){return{tags:{callback:function(t){return _.any(this.get("tags"),function(e){return 0<=e.indexOf(t)})}},text:{callback:function(t){return t=t.toLowerCase(),0<=this.get("title").toLowerCase().indexOf(t)||_.any(this.get("tags"),function(e){return 0<=e.indexOf(t)})}},type:{callback:function(e){return this.get("type")===e}}}},this.showModal=function(){r.getModal().showModal(),r.showTemplatesView()},this.closeModal=function(){this.getModal().hideModal()},this.getModal=function(){return e=e||new h.Modal},this.init=function(){r.setFilter("type","section",!0),u.on("preview:loaded",d.bind(this))},this.getTabs=function(){var i=this.getFilter("type"),a={section:{title:"Blocks"},page:{title:"Pages"}};return _.each(a,function(e,t){i===t&&(a[i].active=!0)}),{tabs:a}},this.getTags=function(){return i},this.getTypeTags=function(){var e=r.getFilter("type");return a[e]},this.showTemplatesView=function(){r.setFilter("tags","",!0),r.setFilter("text","",!0),n?r.getModal().showTemplatesView(n):r.loadTemplates(function(){r.getModal().showTemplatesView(n)})},this.showPreviewView=function(e){r.getModal().showPreviewView(e)},this.loadTemplates=function(e){r.requestLibraryData({onBeforeUpdate:r.getModal().showLoadingView.bind(r.getModal()),onUpdate:function(){r.getModal().hideLoadingView(),e&&e()}})},this.requestLibraryData=function(t){var e;n&&!t.forceUpdate?t.onUpdate&&t.onUpdate():(t.onBeforeUpdate&&t.onBeforeUpdate(),e={data:{},success:function(e){n=new h.Collections.Template(e.templates),e.tags&&(i=e.tags),e.type_tags&&(a=e.type_tags),t.onUpdate&&t.onUpdate()}},t.forceSync&&(e.data.sync=!0),elementorCommon.ajax.addRequest("get_ha_library_data",e))},this.requestTemplateData=function(e,t){e={unique_id:e,data:{edit_mode:!0,display:!0,template_id:e}};t&&jQuery.extend(!0,e,t),elementorCommon.ajax.addRequest("get_ha_template_data",e)},this.insertTemplate=function(e){var i=e.model,a=this;a.getModal().showLoadingView(),a.requestTemplateData(i.get("template_id"),{success:function(e){a.getModal().hideLoadingView(),a.getModal().hideModal();var t={};-1!==a.atIndex&&(t.at=a.atIndex),$e.run("document/elements/import",{model:i,data:e,options:t}),a.atIndex=-1},error:function(e){a.showErrorDialog(e)},complete:function(e){a.getModal().hideLoadingView(),window.elementor.$previewContents.find(".elementor-add-section .elementor-add-section-close").click()}})},this.showErrorDialog=function(e){var t;"object"===_typeof(e)?(t="",_.each(e,function(e){t+="<div>"+e.message+".</div>"}),e=t):e?e+=".":e="<i><The error message is empty></i>",r.getErrorDialog().setMessage('The following error(s) occurred while processing the request:<div id="elementor-template-library-error-info">'+e+"</div>").show()},this.getErrorDialog=function(){return t=t||elementorCommon.dialogsManager.createWidget("alert",{id:"elementor-template-library-error-dialog",headerMessage:"An error occurred"})}},n.library=new h.Manager,n.library.init(),window.ha=n}(jQuery,window.elementor,window.ha||{});