11 lines
3.2 KiB
JavaScript
11 lines
3.2 KiB
JavaScript
/**
|
|
* Copyright (c) Tiny Technologies, Inc. All rights reserved.
|
|
* Licensed under the LGPL or a commercial license.
|
|
* For LGPL see License.txt in the project root for license information.
|
|
* For commercial licenses see https://www.tiny.cloud/
|
|
*
|
|
* Version: 5.0.4 (2019-04-23)
|
|
*/
|
|
|
|
!function(o){"use strict";var a=function(t){var e=t,r=function(){return e};return{get:r,set:function(t){e=t},clone:function(){return a(r())}}},t=tinymce.util.Tools.resolve("tinymce.PluginManager"),n=tinymce.util.Tools.resolve("tinymce.util.Delay"),i=tinymce.util.Tools.resolve("tinymce.util.LocalStorage"),u=tinymce.util.Tools.resolve("tinymce.util.Tools"),s=function(t,e){var r=t||e,n=/^(\d+)([ms]?)$/.exec(""+r);return(n[2]?{s:1e3,m:6e4}[n[2]]:1)*parseInt(r,10)},f=function(t){var e=t.getParam("autosave_prefix","tinymce-autosave-{path}{query}{hash}-{id}-");return e=(e=(e=(e=e.replace(/\{path\}/g,o.document.location.pathname)).replace(/\{query\}/g,o.document.location.search)).replace(/\{hash\}/g,o.document.location.hash)).replace(/\{id\}/g,t.id)},c=function(t,e){var r=t.settings.forced_root_block;return""===(e=u.trim(void 0===e?t.getBody().innerHTML:e))||new RegExp("^<"+r+"[^>]*>((\xa0| |[ \t]|<br[^>]*>)+?|)</"+r+">|<br>$","i").test(e)},l=function(t){var e=parseInt(i.getItem(f(t)+"time"),10)||0;return!((new Date).getTime()-e>s(t.settings.autosave_retention,"20m")&&(m(t,!1),1))},m=function(t,e){var r=f(t);i.removeItem(r+"draft"),i.removeItem(r+"time"),!1!==e&&t.fire("RemoveDraft")},v=function(t){var e=f(t);!c(t)&&t.isDirty()&&(i.setItem(e+"draft",t.getContent({format:"raw",no_events:!0})),i.setItem(e+"time",(new Date).getTime().toString()),t.fire("StoreDraft"))},d=function(t){var e=f(t);l(t)&&(t.setContent(i.getItem(e+"draft"),{format:"raw"}),t.fire("RestoreDraft"))},g=function(t,e){var r=s(t.settings.autosave_interval,"30s");e.get()||(n.setInterval(function(){t.removed||v(t)},r),e.set(!0))},y=function(t){t.undoManager.transact(function(){d(t),m(t)}),t.focus()};function p(n){for(var o=[],t=1;t<arguments.length;t++)o[t-1]=arguments[t];return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=o.concat(t);return n.apply(null,r)}}var D=tinymce.util.Tools.resolve("tinymce.EditorManager");D._beforeUnloadHandler=function(){var e;return u.each(D.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};var h=function(r,t){return function(t){t.setDisabled(!l(r));var e=function(){return t.setDisabled(!l(r))};return r.on("StoreDraft RestoreDraft RemoveDraft",e),function(){return r.off("StoreDraft RestoreDraft RemoveDraft",e)}}};t.add("autosave",function(t){var e,r,n=a(!1);return o.window.onbeforeunload=D._beforeUnloadHandler,g(e=t,n),e.ui.registry.addButton("restoredraft",{tooltip:"Restore last draft",icon:"restore-draft",onAction:function(){y(e)},onSetup:h(e)}),e.ui.registry.addMenuItem("restoredraft",{text:"Restore last draft",icon:"restore-draft",onAction:function(){y(e)},onSetup:h(e)}),t.on("init",function(){t.getParam("autosave_restore_when_empty",!1)&&t.dom.isEmpty(t.getBody())&&d(t)}),{hasDraft:p(l,r=t),storeDraft:p(v,r),restoreDraft:p(d,r),removeDraft:p(m,r),isEmpty:p(c,r)}}),function e(){}}(window);
|