!function(){var t={900:function(t){var e;e=jQuery,t.exports={templateSettings:{escape:/<#-([\s\S]+?)#>/g,evaluate:/<#([\s\S]+?)#>/g,interpolate:/<#=([\s\S]+?)#>/g},tpl:function(t,s){var i=[e("script#"+t.replace(/\//g,"-")).html()||""];return i.push(this.templateSettings),s?_.template.apply(_,i)(s):_.template.apply(_,i)}}},165:function(t,e,s){t.exports={Products:Backbone.Collection.extend({model:s(564).Product,buildDependencies:function(){var t=this;function e(e){return t.findWhere({tag:e})}this.each((function(t){var s=t.get("dependencies");s&&s.length&&(t.dependencies=s.map(e))})),this.models.forEach((function(e){e.dependencies&&e.dependencies.forEach((function(e){t.remove(e),e.isDependedUpon=!0}))})),this.models.forEach((function(e,s){e.dependencies&&t.add(e.dependencies,{at:s})}))},product_purchased:function(){var t=this.where({status:"available"});return this.length-t.length}}),Messages:Backbone.Collection.extend({initialize:function(t){},display:function(){this.each((function(t,e,s){TPM.Notification[t.get("status")](t.get("message"))}),this)}})}},651:function(t,e,s){jQuery,t.exports={ClientMode:s(803)}},803:function(t){var e;e=jQuery,t.exports=Backbone.View.extend({template:TPM.tpl("modals/client-mode"),className:"tpm-modal",events:{"click .close":"close","click .tpm-modal-submit":"submit","click .tpm-modal-cancel":"close"},initialize:function(){this.render()},render:function(){this.$el.html(this.template({model:this.model}))},close:function(){this.remove()},open:function(){this._get_body().append(this.$el).addClass("tpm-modal-visible")},_get_body:function(){return(!this.$body||this.$body.length<=0)&&(this.$body=e("body")),this.$body},submit:function(){this.$(".close").remove(),this.$(".tpm-button-gray").remove(),this.$(".tpm-modal-submit").attr("disabled","disabled").html("Loading..."),e.ajax({url:ajaxurl,type:"post",data:{action:"tpm_client_mode"},complete:function(){window.location.reload()}})}})},564:function(t,e,s){t.exports={Product:s(492)}},492:function(t){var e;e=jQuery,t.exports=Backbone.Model.extend({defaults:{description:"product description"},is_skin:function(){return"skin"===this.get("type")},install_and_activate:function(t){var s=this,i="ttb"===s.get("tag"),n=i?1:0;function a(t,e,i,n,a,o){t&&e{n().then(a).catch(o)}),500)):o({model:s,response:response?response.data:null})}return function o(){return s.set("status","installing"),new Promise(((l,c)=>{e.ajax({url:ajaxurl,type:"post",data:{action:"tpm_install_and_activate_product",credentials:t.toJSON(),tag:s.get("tag")},success:function(t){!0===t.success?l({model:s,response:t.data}):a(i,0,n,o,l,c)},error:function(t){a(i,0,n,o,l,c)}})}))}()},activate:function(){var t=this;return new Promise((function(s,i){t.set("status","Activating..."),e.ajax({url:ajaxurl,type:"post",data:{action:"tpm_activate_product",tag:t.get("tag")},success:function(e){!0===e.success?s({model:t,response:e.data}):i({model:t,response:e.data})},error:function(e){i({model:t,response:e.data})}})}))},get_status:function(){var t={to_install:"Queued",to_license:"To be licensed",installed:"Installed",installing:"Processing",failed:"Failed",activating:"Activating",activated:"Activated",to_activate:"Queued",not_installed:"Not Installed",not_activated:"Not Activated",not_licensed:"Not Licensed",ready:"Ready to use"};return t[this.get("status")]?t[this.get("status")]:this.get("message")},productOrTheme:function(){return"plugin"===this.get("type")?"Product":"Theme"}})},101:function(t,e,s){jQuery,t.exports={Product:s(494),ProductList:s(613),ProductManager:s(405),ItemStatus:s(219),BottomBar:s(317),Notification:s(875)}},317:function(t){var e,s;e=jQuery,(s=(s=window.wp)||{}).updates=s.updates||{},t.exports=Backbone.View.extend({template:TPM.tpl("bottom-bar"),events:{"click button#tpm-install":function(t){var i=new Backbone.Collection(this.collection.where({checked:!0}));s.updates.shouldRequestFilesystemCredentials&&i.where({status:"to_install"}).length>0?s.updates.filesystemCredentials.available?this[t.currentTarget.dataset.fn](this.read_credentials(),i):(s.updates.maybeRequestFilesystemCredentials(t),e("#request-filesystem-credentials-dialog").off("submit","form").on("submit","form",_.bind((function(n){n.preventDefault(),s.updates.filesystemCredentials.ftp.hostname=e("#hostname").val(),s.updates.filesystemCredentials.ftp.username=e("#username").val(),s.updates.filesystemCredentials.ftp.password=e("#password").val(),s.updates.filesystemCredentials.ftp.connectionType=e('input[name="connection_type"]:checked').val(),s.updates.filesystemCredentials.ssh.publicKey=e("#public_key").val(),s.updates.filesystemCredentials.ssh.privateKey=e("#private_key").val(),s.updates.filesystemCredentials.fsNonce=e("#_fs_nonce").val(),s.updates.filesystemCredentials.available=!0,s.updates.ajaxLocked=!1,s.updates.requestForCredentialsModalClose(),this[t.currentTarget.dataset.fn](this.read_credentials(),i)}),this))):this[t.currentTarget.dataset.fn](this.read_credentials(),i)},"click button#tpm-back":function(t){var e=t.currentTarget.getAttribute("data-redirect");window.location=e||TPM.tpm_url}},initialize:function(){this.$el.attr("id","tpm-bottom-bar"),this.$el.html(this.template()),this.listenTo(this.collection,"change:checked",this.update_button),this.$action_button=this.$("#tpm-install").first(),this.$back_button=this.$("#tpm-back").first()},update_button:function(){var t=new Backbone.Collection(this.collection.where({checked:!0})),e=t.length;this.$action_button.find("span").last().text("("+e+")"),e<=0?this.$action_button.attr("disabled","disabled"):this.$action_button.removeAttr("disabled");var s=_.uniq(t.pluck("status")),i={to_install:"Install",to_activate:"Activate",to_license:"License"},n="";n=Object.values(s.slice(0,s.length-1)).join(", "),s.length>=2&&(n+=" and "),n+=s[s.length-1]||"",Object.keys(i).map((function(t){n=n.replace(t,i[t])})),this.$action_button.find("span").first().text(n+" selected products")},install:function(t,e){TPM.ProductList.remove(),this.product_manager=new TPM.Views.ProductManager({collection:e,model:t}),this.installing_button(),this.product_manager.install_and_activate(),TPM.$app.prepend(this.product_manager.$el)},installing_button:function(){this.$action_button.html("Installing products…").addClass("tpm-spin-it").attr("disabled","disabled")},activating_button:function(){this.$action_button.attr("disabled","disabled").html("Activating products… ").addClass("tpm-spin-it")},showThriveDashboardButton:function(){this.$back_button.html(TPM.t.go_to_TD).attr("data-redirect",TPM.tve_dash_url)},showTTBActivationButton:function(){this.toggle_back_button(!1),this.activate_button("Activate Thrive Theme Builder"),this.$action_button.addClass("blue-button")},showTTBDashboardButton:function(){this.$action_button.hide(),this.$back_button.html(TPM.t.go_to_TTB_dashboard).attr("data-redirect",TPM.ttb_url).show()},activation_complete_button:function(){this.$action_button.removeClass("tpm-spin-it").removeAttr("disabled").attr("data-fn","reload").html("Back to dashboard")},activate_button:function(t){this.$action_button.attr("data-fn","activate").removeAttr("disabled").removeClass("tpm-spin-it").html(t||"Activate products").show()},activate:function(){this.activating_button(),this.product_manager.execute_activation()},toggle_back_button:function(t){void 0===t&&(t=!1);var e=t?"show":"hide";this.$back_button[e]()},reload:function(){return window.location.reload()},read_credentials:function(){var t=_.extend(_defaults={connection_type:"",hostname:"",username:"",password:"",_fs_nonce:""},{hostname:s.updates.filesystemCredentials.ftp.hostname,username:s.updates.filesystemCredentials.ftp.username,password:s.updates.filesystemCredentials.ftp.password,connection_type:s.updates.filesystemCredentials.ftp.connectionType,public_key:s.updates.filesystemCredentials.ssh.publicKey,private_key:s.updates.filesystemCredentials.ssh.privateKey,_fs_nonce:s.updates.filesystemCredentials.fsNonce});return new Backbone.Model(t)}})},219:function(t){jQuery,t.exports=Backbone.View.extend({className:"tpm-status-item",template:TPM.tpl("install/item-status"),initialize:function(){this.listenTo(this.model,"change",this.status_changed),this.render(),this.$status=this.$(".tpm-product-status"),this.$extra=this.$(".tpm-status-extra")},render:function(){this.$el.html(this.template({model:this.model}))},status_changed:function(){this.$status.attr("class","tpm-product-status tpm-"+this.model.get("status")),this.$status.html(this.model.get_status()),this.$extra.html(this.model.get("extra")||"").attr("class","tpm-status-extra tpm-"+this.model.get("status"))}})},875:function(t){var e;e=jQuery,t.exports=Backbone.View.extend({template:TPM.tpl("notification"),events:{"click #tpm-close-notification":"hide"},display_time:10,initialize:function(){this.$el.attr("id","tpm-notification-box"),this.render()},render:function(){this.$el.html(this.template()),e("body").append(this.$el)},success:function(t){this.$("h3").text("Success!"),this.$el.addClass("tpm-success"),this.$("p").html(t),this.show()},error:function(t){this.$("h3").text("Ooops!"),this.$el.addClass("tpm-error"),this.$("p").html(t),this.show()},warning:function(t){this.$("h3").text("Warning"),this.$el.addClass("tpm-notice"),this.$("p").html(t),this.show()},show:function(){this.$el.addClass("tpm-show"),this.timeout=setTimeout(_.bind(this.hide,this),1e3*this.display_time)},hide:function(){clearTimeout(this.timeout),this.$el.removeClass("tpm-show tpm-error tpm-notice tpm-success")}})},613:function(t){var e;e=jQuery,t.exports=Backbone.View.extend({template:TPM.tpl("product/list"),$plugins_list:null,$themes_list:null,$skins_list:null,plugins:null,themes:null,skins:null,events:{'change input[type="checkbox"]':function(t){var e=t.currentTarget;"function"==typeof this[e.dataset.fn]?this[e.dataset.fn](e.dataset.args):"plugin"!==e.dataset.type&&"theme"!==e.dataset.type&&"skin"!==e.dataset.type||this.manage_select_deselect(e.dataset.type+"s")},"click .tpm-toggle":function(t){var s=this.$(t.currentTarget.dataset.toggle);s.hasClass("tpm-hidden")?(s.slideDown(200,(function(){e(t.currentTarget).find("span").last().html("-")})),s.removeClass("tpm-hidden")):(s.slideUp(200,(function(){e(t.currentTarget).find("span").last().html("+")})),s.addClass("tpm-hidden"))}},initialize:function(){this.$el.html(this.template()),this.$el.attr("id","tpl-product-list"),this.$plugins_list=this.$("#tpm-plugins-list"),this.$themes_list=this.$("#tpm-themes-list"),this.$skins_list=this.$("#tpm-skins-list"),this.collection.length<=0||(this.plugins=new Backbone.Collection(this.collection.where({type:"plugin"})),this.themes=new Backbone.Collection(this.collection.where({type:"theme"})),this.skins=new Backbone.Collection(this.collection.where({type:"skin"})),this.skins.length||(this.$("#tpm-skins-wrapper").hide(),this.$(".tpm-toggle").click()),this.render(),this.collection.product_purchased()<=0&&TPM.Notification.warning("It looks like you don't have any activations. You can manage your activations from Thrive Themes account"))},select_all:function(t){if(this[t]instanceof Backbone.Collection){var e=this[t].filter((function(t){var e=t.get("status");return"ready"!==e&&"available"!==e&&"activated"!==e}));if(_.each(e,(function(t){t.set("checked",!0)})),"themes"===t){var s=this[t].findWhere({tag:"ttb"});s instanceof Backbone.Model&&(s.attributes.checked=!1)}this.$("#tpm-"+t+"-select-all").prop("checked",!0),this.$("#tpm-"+t+"-deselect-all").prop("checked",!1)}},deselect_all:function(t){this[t]instanceof Backbone.Collection&&(this[t].each((function(t){t.set("checked",!1)})),this.$("#tpm-"+t+"-deselect-all").prop("checked",!0),this.$("#tpm-"+t+"-select-all").prop("checked",!1))},manage_select_deselect:function(t){if("themes"===t||"plugins"===t||"skin"===t){var e=this[t].filter((function(t){var e=t.get("status");return"ready"!==e&&"available"!==e})).length,s=this[t].where({checked:!0}).length;0===s?(this.$("#tpm-"+t+"-deselect-all").prop("checked",!0),this.$("#tpm-"+t+"-select-all").prop("checked",!1)):s===e?(this.$("#tpm-"+t+"-deselect-all").prop("checked",!1),this.$("#tpm-"+t+"-select-all").prop("checked",!0)):(this.$("#tpm-"+t+"-deselect-all").prop("checked",!1),this.$("#tpm-"+t+"-select-all").prop("checked",!1))}},render:function(){this.plugins.each((function(t){var e=new TPM.Views.Product({model:t});"Thrive Automator"!==e.model.attributes.name&&this.$plugins_list.append(e.$el)}),this),this.themes.each((function(t){if(!0!==t.get("hidden")){var e=new TPM.Views.Product({model:t});this.$themes_list.append(e.$el)}}),this);var t=new TPM.Views.Product({model:this.collection.findWhere({tag:"ttb"})});this.$skins_list.append(t.$el);var e=this.manage_options("plugins"),s=this.manage_options("themes"),i=this.manage_options("skins");e&&this.$("#tpm-plugins-deselect-all").prop("checked",!0),s&&this.$("#tpm-themes-deselect-all").prop("checked",!0),i&&this.$("#tpm-skins-deselect-all").prop("checked",!0),TPM.BottomBar.update_button()},manage_options:function(t){if("plugins"!==t&&"themes"!==t&&"skins"!==t)throw new Error("Invalid type to manage options for themes|plugins");var e=this[t].where({status:"ready"}).length+this[t].where({status:"available"}).length+this[t].where({status:"activated"}).length+this[t].where({hidden:!0}).length;return!((e=parseInt(e))>=this[t].length&&(this.$('label[for="tpm-'+t+'-select-all"]').addClass("tpm-disabled").find("input").attr("disabled","disabled").prop("checked",!1),this.$('label[for="tpm-'+t+'-deselect-all"]').addClass("tpm-disabled").find("input").attr("disabled","disabled").prop("checked",!1),1))}})},405:function(t){var e;e=jQuery,t.exports=Backbone.View.extend({className:"tpm-product-manager",template:TPM.tpl("product/product-manager"),initialize:function(){this.render()},render:function(){this.$el.html(this.template())},execute_install:function(){TPM.BottomBar.toggle_back_button(!1);var t=this,e=function(t){t.set("status","installed")},s=function(t){t.set("status","failed")};this.collection.each((function(t,e,s){var i=new TPM.Views.ItemStatus({model:t});this.$el.append(i.$el)}),this),Promise.resolve().then((function(){return t.collection.reduce((function(t,i){return t.then((function(){return i.install()})).then(e,s)}),Promise.resolve())})).then((function(){t.collection.where({status:"failed"}).length?TPM.Notification.warning("Some of the products could not be installed. Please try again!"):TPM.Notification.success("The selected products were installed successfully."),t.$("h1").text("Activate products"),TPM.BottomBar.activate_button(),TPM.BottomBar.toggle_back_button(!0)}))},install_and_activate:function(){TPM.BottomBar.toggle_back_button(!1);var t=this,e=this.collection.length,s=function(t){var e=t.model&&t.model instanceof Backbone.Model?t.model:null,s=t.response&&t.response.status?t.response.status:null;e&&s&&(e.set("status",s),e.set("message",t.response.message),e.set("extra",t.response&&t.response.extra),e.dependencies&&e.dependencies.length&&e.dependencies.forEach((function(t){t.set("status",s)})))};this.collection.each((function(t,e,s){var i=new TPM.Views.ItemStatus({model:t});this.$el.append(i.$el)}),this),Promise.resolve().then((function(){return t.collection.reduce((function(e,i){return e.then((function(){return i.install_and_activate(t.model)})).then(s,s)}),Promise.resolve())})).then((function(){var s=t.collection.filter((function(t){return"ready"===t.get("status")||"installed"===t.get("status")})),i=t.collection.filter((function(t){return"ready"===t.get("status")})),n=t.collection.filter((function(t){return"installed"===t.get("status")}));s.length!==e?TPM.Notification.warning("Some of the products could not be installed and register. Please try again!"):i.length===e?TPM.Notification.success(1===i.length?"The selected product was activated successfully.":"The selected products were activated successfully."):n.length===e?TPM.Notification.success(1===n.length?"The selected product was installed successfully.":"The selected products were installed successfully."):TPM.Notification.success("The selected products were installed successfully."),TPM.BottomBar.$action_button.hide(),TPM.BottomBar.toggle_back_button(!0),t.collection.where({status:"ready"}).length&&TPM.BottomBar.showThriveDashboardButton(),t.handleThemeButton(t.collection)}))},handleThemeButton:function(t){var e=t.findWhere({tag:"ttb"});if(e){var s=e.get("status");"installed"===s?TPM.BottomBar.showTTBActivationButton():"ready"===s&&TPM.BottomBar.showTTBDashboardButton()}},execute_activation:function(){TPM.BottomBar.toggle_back_button(!1);var t=new Backbone.Collection(this.collection.where({status:"installed"}));t.each((function(t){t.set("status","activating")})),e.ajax({url:ajaxurl,type:"post",data:{action:"tpm_activate_products",tags:t.pluck("tag")},success:function(e){if(!0!==e.success)return _.each(e.data,(function(e,s){var i=t.findWhere({tag:e});i instanceof Backbone.Model&&i.set("status","failed")})),TPM.Notification.error("Something went wrong and products could not be activated. Please try again or contact our support team!");var s=!0;_.each(e.data,(function(t){!0===s&&!1===t&&(s=!1)})),!0===s?(t.each((function(t){t.set("status","activated")})),TPM.Notification.success("The selected products were activated successfully."),t.filter((function(t){return"ttb"===t.get("tag")&&"activated"===t.get("status")})).length&&TPM.BottomBar.showTTBDashboardButton()):(_.each(e.data,(function(e,s){var i=t.findWhere({tag:s});i instanceof Backbone.Model&&i.set("status",!0===e?"activated":"failed")})),TPM.Notification.warning("Some products could not be activated. Please try again or contact our support team!"))},error:function(){return TPM.Notification.error("Something went wrong. The activation request could not be made!")},complete:function(){TPM.BottomBar.activation_complete_button()}})}})},494:function(t){jQuery,t.exports=Backbone.View.extend({className:"tpm-product-elem",template:TPM.tpl("product/item"),skin_template:TPM.tpl("product/skin"),events:{'click input[type="checkbox"]':function(t){this.model.set("checked",t.currentTarget.checked)}},initialize:function(){this.listenTo(this.model,"change:checked",(function(t){this.$('input[type="checkbox"]').prop("checked",!!this.model.get("checked")),t.dependencies&&t.dependencies.forEach((function(e){e.set("checked",!!t.get("checked"))}))})),this.$el.attr("id",this.model.get("tag")),this.render()},render:function(){var t=this.model.is_skin()?this.skin_template:this.template;this.model.is_skin()&&this.$el.addClass("ttb-skin"),this.$el.html(t({model:this.model})),this.render_options()},render_footer:function(t){var e={available:TPM.tpl("product/status/available"),activated:TPM.tpl("product/status/activated"),to_install:TPM.tpl("product/status/to_install"),to_activate:TPM.tpl("product/status/to_activate"),to_license:TPM.tpl("product/status/to_license"),ready:TPM.tpl("product/status/installed")};return"function"!=typeof e[t]?"":e[t]({model:this.model})},render_options:function(){this.$el.append(this.render_footer(this.model.get("status"))),"available"===this.model.get("status")?this.$el.addClass("not-purchased"):this.$el.addClass(this.model.get("status"))}})}},e={};function s(i){var n=e[i];if(void 0!==n)return n.exports;var a=e[i]={exports:{}};return t[i](a,a.exports,s),a.exports}!function(t){var e=window.TPM||{};e.Views=e.Views||{},e.Models=e.Models||{},e.Collections=e.Collections||{},e.Modals=e.Modals||{},t.extend(e,s(900)),t((function(){if(e.$app=t("#tpm-app"),!(e.$app.length<=0)){Backbone.emulateHTTP=!0,t.extend(e.Views,s(101)),t.extend(e.Models,s(564)),t.extend(e.Collections,s(165)),t.extend(e.Modals,s(651)),e.Notification=new e.Views.Notification;var i=new e.Collections.Products(e.products);i.buildDependencies(),new e.Collections.Messages(e.messages).display(),e.BottomBar=new e.Views.BottomBar({collection:i}),e.ProductList=new e.Views.ProductList({collection:i}),t("#tpm-client-mode").on("click",(function(){(new e.Modals.ClientMode).open()})),e.$app.html(e.ProductList.$el),e.$app.append(e.BottomBar.$el)}}))}(jQuery)}();