tinymce.PluginManager.add("autosave",function(e){function t(e,t){var n={s:1e3,m:6e4};return e=/^(\d+)([ms]?)$/.exec(""+(e||t)),(e[2]?n[e[2]]:1)*parseInt(e,10)}function n(){var e=parseInt(f.getItem(h+"autosave.time"),10)||0;return(new Date).getTime()-e>d.autosave_retention?(i(!1),!1):!0}function i(t){f.removeItem(h+"autosave.draft"),f.removeItem(h+"autosave.time"),t!==!1&&e.fire("RemoveDraft")}function a(){c()||(f.setItem(h+"autosave.draft",e.getContent({format:"raw",no_events:!0})),f.setItem(h+"autosave.time",(new Date).getTime()),e.fire("StoreDraft"))}function r(){n()&&(e.setContent(f.getItem(h+"autosave.draft"),{format:"raw"}),e.fire("RestoreDraft"))}function o(){m||(setInterval(function(){e.removed||a()},d.autosave_interval),m=!0)}function s(){var t=this;t.disabled(!n()),e.on("StoreDraft RestoreDraft RemoveDraft",function(){t.disabled(!n())}),o()}function l(){e.undoManager.beforeChange(),r(),i(),e.undoManager.add()}function u(){var e;return tinymce.each(tinymce.editors,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}function c(t){var n=e.settings.forced_root_block;return t=tinymce.trim("undefined"==typeof t?e.getBody().innerHTML:t),""===t||new RegExp("^<"+n+">(( | |[ ]|
]*>)+?|)"+n+">|
$","i").test(t)}var m,d=e.settings,f=tinymce.util.LocalStorage,h=e.id;d.autosave_interval=t(d.autosave_interval,"30s"),d.autosave_retention=t(d.autosave_retention,"20m"),e.addButton("restoredraft",{title:"Restore last draft",onclick:l,onPostRender:s}),e.addMenuItem("restoredraft",{text:"Restore last draft",onclick:l,onPostRender:s,context:"file"}),e.settings.autosave_restore_when_empty!==!1&&(e.on("init",function(){n()&&c()&&r()}),e.on("saveContent",function(){i()})),window.onbeforeunload=u,this.hasDraft=n,this.storeDraft=a,this.restoreDraft=r,this.removeDraft=i,this.isEmpty=c});