jQuery(function(e){e("#adminForm").on("submit",function(a){"page.cancel"!=e("#form_task").val()&&a.preventDefault()});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},e("#btn-save-page, #sp-pagebuilder-btn-save, #btn-save-copy, #btn-save-new, #btn-save-close").on("click",function(a){a.preventDefault();var n=e(this),t=e("#adminForm"),i="page.apply";"btn-save-copy"==a.target.id&&(i="page.save2copy"),e("#form_task").val(i),e.ajax({type:"POST",url:pagebuilder_base+"administrator/index.php?option=com_sppagebuilder&task=page."+i,data:t.serialize(),beforeSend:function(){n.find(".fa-save").removeClass("fa-save").addClass("fa-spinner fa-spin")},success:function(t){try{var i=e.parseJSON(t);n.find(".fa").removeClass("fa-spinner fa-spin").addClass("fa-save");o="success";if(!i.status)var 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 a=e(this);setTimeout(function(){a.animate({opacity:0,"margin-top":-15,"margin-bottom":0},200,function(){a.remove()})},3e3)}),!i.status)return;window.history.replaceState("","",i.redirect),i.frontend_editor_url&&(0===e("#btn-page-frontend-editor").length?e("#btn-page-options").parent().before('<div class="sp-pagebuilder-btn-group"><a id="btn-page-frontend-editor" target="_blank" href="'+i.frontend_editor_url+'" class="sp-pagebuilder-btn sp-pagebuilder-btn-info"><i class="fa fa-edit"></i> '+Joomla.JText._("COM_SPPAGEBUILDER_FRONTEND_EDITOR")+"</a></div>\n"):e("#btn-page-frontend-editor").attr("href",i.frontend_editor_url)),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-inverse"><i class="fa fa-eye"></i> '+Joomla.JText._("COM_SPPAGEBUILDER_PREVIEW")+"</a></div>\n"):e("#btn-page-preview").attr("href",i.preview_url)),"btn-save-new"==a.target.id&&(window.location.href="index.php?option=com_sppagebuilder&view=page&layout=edit"),"btn-save-close"==a.target.id&&(window.location.href="index.php?option=com_sppagebuilder&view=pages")}catch(e){window.location.href="index.php?option=com_sppagebuilder&view=pages"}}})})});