/**
* @package SP Page Builder
* @author JoomShaper http://www.joomshaper.com
* @copyright Copyright (c) 2010 - 2021 JoomShaper
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
jQuery((function(e){e(".sp-pagebuilder-form-group-toggler").find(">span").on("click",(function(t){t.preventDefault(),e(this).parent().hasClass("active")?e(this).parent().removeClass("active"):(e(".sp-pagebuilder-form-group-toggler").removeClass("active"),e(this).parent().addClass("active"))}));window.onbeforeunload=function(e){if(void 0!==window.warningAtReload&&1==window.warningAtReload){var t="Do you want to lose unsaved data?";return(e=e||window.event)&&(e.returnValue=t),t}return null},e(document).on("click","#btn-save-page",(function(t){t.preventDefault();var a=e(this),n=e.parseJSON(e("#jform_sptext").val());n.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)}))}))})),e("#jform_sptext").val(JSON.stringify(n));var i=e("#adminForm"),o=e("#sp-page-builder").data("pageid");e.ajax({type:"POST",url:pagebuilder_base+"index.php?option=com_sppagebuilder&task=page.apply&pageId="+o,data:i.serialize(),beforeSend:function(){a.find(".fa-save").removeClass("fa-save").addClass("fa-spinner fa-spin")},success:function(n){try{var i=e.parseJSON(n);a.find(".fa").removeClass("fa-spinner fa-spin").addClass("fa-save"),0===e(".sp-pagebuilder-notifications").length&&e('<div class="sp-pagebuilder-notifications"></div>').appendTo("body");var o="success";if(!i.status)o="error";if(i.title&&e("#jform_title").val(i.title),i.id&&e("#jform_id").val(i.id),e('<div class="notify-'+o+'">'+i.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),e(".sp-pagebuilder-notifications").find(">div").each((function(){var t=e(this);setTimeout((function(){t.animate({opacity:0,"margin-top":-15,"margin-bottom":0},200,(function(){t.remove()}))}),3e3)})),!i.status)return;i.preview_url&&0===e("#btn-page-preview").length&&e("#btn-page-options").parent().before('<div class="sp-pagebuilder-btn-group"><a id="btn-page-preview" target="_blank" href="'+i.preview_url+'" class="sp-pagebuilder-btn sp-pagebuilder-btn-primary"><i class="fa fa-eye"></i> Preview</a></div>'),"btn-save-new"==t.target.id&&(window.location.href="index.php?option=com_sppagebuilder&view=page&layout=edit"),"btn-save-close"==t.target.id&&(window.location.href="index.php?option=com_sppagebuilder&view=pages")}catch(e){window.location.href="index.php?option=com_sppagebuilder&view=pages"}}})}))}));