PHP Classes

File: public/js/tinymce/src/plugins/autosave/src/main/js/core/Storage.js

Recommend this page to a friend!
  Classes of Abed Nego Ragil Putra   GoLavaCMS   public/js/tinymce/src/plugins/autosave/src/main/js/core/Storage.js   Download  
File: public/js/tinymce/src/plugins/autosave/src/main/js/core/Storage.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: GoLavaCMS
Publish content on Web pages with SEO support
Author: By
Last change:
Date: 6 years ago
Size: 2,937 bytes
 

Contents

Class file image Download
/** * Storage.js * * Released under LGPL License. * Copyright (c) 1999-2017 Ephox Corp. All rights reserved * * License: http://www.tinymce.com/license * Contributing: http://www.tinymce.com/contributing */ define( 'tinymce.plugins.autosave.core.Storage', [ 'global!setInterval', 'tinymce.core.util.LocalStorage', 'tinymce.core.util.Tools', 'tinymce.plugins.autosave.api.Events', 'tinymce.plugins.autosave.api.Settings' ], function (setInterval, LocalStorage, Tools, Events, Settings) { var isEmpty = function (editor, html) { var forcedRootBlockName = editor.settings.forced_root_block; html = Tools.trim(typeof html === "undefined" ? editor.getBody().innerHTML : html); return html === '' || new RegExp( '^<' + forcedRootBlockName + '[^>]*>((\u00a0|&nbsp;|[ \t]|<br[^>]*>)+?|)<\/' + forcedRootBlockName + '>|<br>$', 'i' ).test(html); }; var hasDraft = function (editor) { var time = parseInt(LocalStorage.getItem(Settings.getAutoSavePrefix(editor) + "time"), 10) || 0; if (new Date().getTime() - time > Settings.getAutoSaveRetention(editor)) { removeDraft(editor, false); return false; } return true; }; var removeDraft = function (editor, fire) { var prefix = Settings.getAutoSavePrefix(editor); LocalStorage.removeItem(prefix + "draft"); LocalStorage.removeItem(prefix + "time"); if (fire !== false) { Events.fireRemoveDraft(editor); } }; var storeDraft = function (editor) { var prefix = Settings.getAutoSavePrefix(editor); if (!isEmpty(editor) && editor.isDirty()) { LocalStorage.setItem(prefix + "draft", editor.getContent({ format: 'raw', no_events: true })); LocalStorage.setItem(prefix + "time", new Date().getTime()); Events.fireStoreDraft(editor); } }; var restoreDraft = function (editor) { var prefix = Settings.getAutoSavePrefix(editor); if (hasDraft(editor)) { editor.setContent(LocalStorage.getItem(prefix + "draft"), { format: 'raw' }); Events.fireRestoreDraft(editor); } }; var startStoreDraft = function (editor, started) { var interval = Settings.getAutoSaveInterval(editor); if (!started.get()) { setInterval(function () { if (!editor.removed) { storeDraft(editor); } }, interval); started.set(true); } }; var restoreLastDraft = function (editor) { editor.undoManager.transact(function () { restoreDraft(editor); removeDraft(editor); }); editor.focus(); }; return { isEmpty: isEmpty, hasDraft: hasDraft, removeDraft: removeDraft, storeDraft: storeDraft, restoreDraft: restoreDraft, startStoreDraft: startStoreDraft, restoreLastDraft: restoreLastDraft }; } );