jQuery(function(o){function t(e,a){0===o(".sp-pagebuilder-notifications").length&&o('<div class="sp-pagebuilder-notifications"></div>').appendTo("body"),o('<div class="notify-'+a+'">'+e+"</div>").css({opacity:0,"margin-top":-15,"margin-bottom":0}).animate({opacity:1,"margin-top":0,"margin-bottom":15},200).prependTo(".sp-pagebuilder-notifications"),o(".sp-pagebuilder-notifications").find(">div").each(function(){var e=o(this);setTimeout(function(){e.animate({opacity:0,"margin-top":-15,"margin-bottom":0},200,function(){e.remove()})},3e3)})}o(".sp-pagebuilder-form-group-toggler").find(">span").on("click",function(e){e.preventDefault(),o(this).parent().hasClass("active")?o(this).parent().removeClass("active"):(o(".sp-pagebuilder-form-group-toggler").removeClass("active"),o(this).parent().addClass("active"))});window.onbeforeunload=function(e){if(void 0!==window.warningAtReload&&1==window.warningAtReload){var a="Do you want to lose unsaved data?";return(e=e||window.event)&&(e.returnValue=a),a}return null},o(document).on("click","#btn-save-page",function(i){i.preventDefault();var n=o(this),e=o.parseJSON(o("#jform_sptext").val());e.filter(function(e){return e.columns.filter(function(e){return e.addons.filter(function(e){return"sp_row"===e.type||"inner_row"===e.type?e.columns.filter(function(e){return e.addons.filter(function(e){return null!=typeof e.htmlContent&&delete e.htmlContent,null!=typeof e.assets&&delete e.assets,e})}):(null!=typeof e.htmlContent&&delete e.htmlContent,null!=typeof e.assets&&delete e.assets,e)})})}),o("#jform_sptext").val(JSON.stringify(e));var a=o("#adminForm"),t=o("#sp-page-builder").data("pageid");o.ajax({type:"POST",url:pagebuilder_base+"index.php?option=com_sppagebuilder&task=page.apply&pageId="+t,data:a.serialize(),beforeSend:function(){n.find(".fa-save").removeClass("fa-save").addClass("fa-spinner fa-spin")},success:function(e){try{var a=o.parseJSON(e);n.find(".fa").removeClass("fa-spinner fa-spin").addClass("fa-save"),0===o(".sp-pagebuilder-notifications").length&&o('<div class="sp-pagebuilder-notifications"></div>').appendTo("body");var t="success";if(!a.status)t="error";if(a.title&&o("#jform_title").val(a.title),a.id&&o("#jform_id").val(a.id),o('<div class="notify-'+t+'">'+a.message+"</div>").css({opacity:0,"margin-top":-15,"margin-bottom":0}).animate({opacity:1,"margin-top":0,"margin-bottom":15},200).prependTo(".sp-pagebuilder-notifications"),void 0!==window.warningAtReload&&1==window.warningAtReload&&(window.warningAtReload=!1),o(".sp-pagebuilder-notifications").find(">div").each(function(){var e=o(this);setTimeout(function(){e.animate({opacity:0,"margin-top":-15,"margin-bottom":0},200,function(){e.remove()})},3e3)}),!a.status)return;window.history.replaceState("","",a.redirect),a.preview_url&&0===o("#btn-page-preview").length&&o("#btn-page-options").parent().before('<div class="sp-pagebuilder-btn-group"><a id="btn-page-preview" target="_blank" href="'+a.preview_url+'" class="sp-pagebuilder-btn sp-pagebuilder-btn-primary"><i class="fa fa-eye"></i> Preview</a></div>'),"btn-save-new"==i.target.id&&(window.location.href="index.php?option=com_sppagebuilder&view=page&layout=edit"),"btn-save-close"==i.target.id&&(window.location.href="index.php?option=com_sppagebuilder&view=pages")}catch(e){window.location.href="index.php?option=com_sppagebuilder&view=pages"}}})}),o(".page-builder-form-menu").on("submit",function(e){e.preventDefault();var a=o(this).serialize();o.ajax({type:"POST",url:pagebuilder_base+"index.php?option=com_sppagebuilder&task=page.addToMenu&pageId="+o("#sp-page-builder").data("pageid"),dataType:"json",cache:!1,data:a,beforeSend:function(){o("#sp-pagebuilder-btn-add-to-menu").find(".fa").removeClass("fa-save").addClass("fa-spinner fa-spin")},success:function(e){o("#sp-pagebuilder-btn-add-to-menu").find(".fa").removeClass("fa-spinner fa-spin").addClass("fa-save"),e.status?(t(e.success,"success"),window.location.href=e.redirect):t(e.error,"error")}.bind(this)})}),o("#jform_menutype").change(function(){var e=o(this).val();o.ajax({url:pagebuilder_base+"index.php?option=com_sppagebuilder&task=page.getMenuParentItem&menutype="+e,dataType:"json"}).done(function(e){o("#jform_menuparent_id option").each(function(){"1"!=o(this).val()&&o(this).remove()}),o.each(e,function(e,a){var t=o("<option>");t.text(a.title).val(a.id),o("#jform_menuparent_id").append(t)}),o("#jform_menuparent_id").trigger("liszt:updated")})})});