!function(){"use strict";functiono(t,e){varr=t||e,n=/^(\d+)([ms]?)$/.exec(""+r);return(n[2]?{s:1e3,m:6e4}[n[2]]:1)*parseInt(r,10)}functionn(t){vare=document.location;returnt.getParam("autosave_prefix","tinymce-autosave-{path}{query}{hash}-{id}-").replace(/{path}/g,e.pathname).replace(/{query}/g,e.search).replace(/{hash}/g,e.hash).replace(/{id}/g,t.id)}functioni(t,e){if(a(e))returnt.dom.isEmpty(t.getBody());varr=d.trim(e);if(""===r)return!0;varn=(newDOMParser).parseFromString(r,"text/html");returnt.dom.isEmpty(n)}functionu(t){vare=parseInt(v.getItem(n(t)+"time"),10)||0;return!((newDate).getTime()-e>o(t.getParam("autosave_retention"),"20m")&&(g(t,!1),1))}functions(t){vare=n(t);!i(t)&&t.isDirty()&&(v.setItem(e+"draft",t.getContent({format:"raw",no_events:!0})),v.setItem(e+"time",(newDate).getTime().toString()),t.fire("StoreDraft"))}functionf(t){vare=n(t);u(t)&&(t.setContent(v.getItem(e+"draft"),{format:"raw"}),t.fire("RestoreDraft"))}functionc(t){t.undoManager.transact(function(){f(t),g(t)}),t.focus()}functionm(r){returnfunction(t){functione(){returnt.setDisabled(!u(r))}returnt.setDisabled(!u(r)),r.on("StoreDraft RestoreDraft RemoveDraft",e),function(){returnr.off("StoreDraft RestoreDraft RemoveDraft",e)}}}vart=tinymce.util.Tools.resolve("tinymce.PluginManager"),a=function(t){returnvoid0===t},l=tinymce.util.Tools.resolve("tinymce.util.Delay"),v=tinymce.util.Tools.resolve("tinymce.util.LocalStorage"),d=tinymce.util.Tools.resolve("tinymce.util.Tools"),g=function(t,e){varr=n(t);v.removeItem(r+"draft"),v.removeItem(r+"time"),!1!==e&&t.fire("RemoveDraft")},y=tinymce.util.Tools.resolve("tinymce.EditorManager");t.add("autosave",function(t){vare,r,n,a;returnt.editorManager.on("BeforeUnload",function(t){vare;d.each(y.get(),function(t){t.plugins.autosave&&t.plugins.autosave.storeDraft(),!e&&t.isDirty()&&t.getParam("autosave_ask_before_unload",!0)&&(e=t.translate("You have unsaved changes are you sure you want to navigate away?"))}),e&&(t.preventDefault(),t.returnValue=e)}),n=e=t,a=o(n.getParam("autosave_interval"),"30s"),l.setEditorInterval(n,function(){s(n)},a),e.ui.registry.addButton("restoredraft",{tooltip:"Restore last draft",icon:"restore-draft",onAction:function(){c(e)},onSetup:m(e)}),e.ui.registry.addMenuItem("restoredraft",{text:"Restore last draft",icon:"restore-draft",onAction:function(){c(e)},onSetup:m(e)}),t.on("init",function(){t.getParam("autosave_restore_when_empty",!1)&&t.dom.isEmpty(t.getBody())&&f(t)}),r=t,{hasDraft:function(){returnu(r)},storeDraft:function(){returns(r)},restoreDraft:function(){returnf(r)},removeDraft:function(t){returng(r,t)},isEmpty:function(t){returni(r,t)}}})}();