CKEDITOR.plugins.add("ipsautosave",{init:function(a){if(a.config.ipsAutoSaveKey&&ips.utils.db.enabled){var d;a.on("instanceReady",function(){setTimeout(function(){var b=ips.utils.db.get("editorSave",a.config.ipsAutoSaveKey),e=parseInt((new Date).getTime().toString().substring(0,10)),g=a.config.ipsDefaultIfNoAutoSave?a.getData():"";_.isArray(b)||(b=[b,e]);var h=parseInt(b[1])+parseInt(e)+172800;if((!a.getData()||a.config.ipsDefaultIfNoAutoSave)&&b[0]&&e<h){a.setData(b[0],function(){ips.utils.lazyLoad.loadContent(a.container.$)});
var c=$("."+a.id).closest("[data-ipsEditor]").find('[data-role\x3d"autoSaveRestoreMessage"]');c.slideDown({queue:!1});var f=function(){c.slideUp();c.find('[data-action\x3d"keepRestoredContents"]').off("click.ipsAutoSave");c.find('[data-action\x3d"clearEditorContents"]').off("click.ipsAutoSave")};c.find('[data-action\x3d"keepRestoredContents"]').on("click.ipsAutoSave",function(){a.focus();f()});c.find('[data-action\x3d"clearEditorContents"]').on("click.ipsAutoSave",function(){a.setData();a.focus();
ips.utils.db.remove("editorSave",a.config.ipsAutoSaveKey);f()});a.once("key",function(){f()});a.once("setData",function(){f()})}d=setInterval(function(){a.getData()!=g?ips.utils.db.set("editorSave",a.config.ipsAutoSaveKey,[a.getData(),e],!0):!a.getData()&&ips.utils.db.get("editorSave",a.config.ipsAutoSaveKey)&&ips.utils.db.remove("editorSave",a.config.ipsAutoSaveKey)},2E3);$("."+a.id).closest("form").on("submit",function(a){window.clearInterval(d)})},100)});a.on("destroy",function(){d&&window.clearInterval(d)})}}});