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