assets/_vendor/tinymce/plugins/autosave/plugin.js in bedrock_sass-0.1.9 vs assets/_vendor/tinymce/plugins/autosave/plugin.js in bedrock_sass-0.2.0

- old
+ new

@@ -1,608 +1,226 @@ (function () { +var autosave = (function () { + 'use strict'; -var defs = {}; // id -> {dependencies, definition, instance (possibly undefined)} - -// Used when there is no 'main' module. -// The name is probably (hopefully) unique so minification removes for releases. -var register_3795 = function (id) { - var module = dem(id); - var fragments = id.split('.'); - var target = Function('return this;')(); - for (var i = 0; i < fragments.length - 1; ++i) { - if (target[fragments[i]] === undefined) - target[fragments[i]] = {}; - target = target[fragments[i]]; - } - target[fragments[fragments.length - 1]] = module; -}; - -var instantiate = function (id) { - var actual = defs[id]; - var dependencies = actual.deps; - var definition = actual.defn; - var len = dependencies.length; - var instances = new Array(len); - for (var i = 0; i < len; ++i) - instances[i] = dem(dependencies[i]); - var defResult = definition.apply(null, instances); - if (defResult === undefined) - throw 'module [' + id + '] returned undefined'; - actual.instance = defResult; -}; - -var def = function (id, dependencies, definition) { - if (typeof id !== 'string') - throw 'module id must be a string'; - else if (dependencies === undefined) - throw 'no dependencies for ' + id; - else if (definition === undefined) - throw 'no definition function for ' + id; - defs[id] = { - deps: dependencies, - defn: definition, - instance: undefined - }; -}; - -var dem = function (id) { - var actual = defs[id]; - if (actual === undefined) - throw 'module [' + id + '] was undefined'; - else if (actual.instance === undefined) - instantiate(id); - return actual.instance; -}; - -var req = function (ids, callback) { - var len = ids.length; - var instances = new Array(len); - for (var i = 0; i < len; ++i) - instances[i] = dem(ids[i]); - callback.apply(null, instances); -}; - -var ephox = {}; - -ephox.bolt = { - module: { - api: { - define: def, - require: req, - demand: dem - } - } -}; - -var define = def; -var require = req; -var demand = dem; -// this helps with minification when using a lot of global references -var defineGlobal = function (id, ref) { - define(id, [], function () { return ref; }); -}; -/*jsc -["tinymce.plugins.autosave.Plugin","ephox.katamari.api.Cell","tinymce.core.PluginManager","tinymce.plugins.autosave.api.Api","tinymce.plugins.autosave.core.BeforeUnload","tinymce.plugins.autosave.ui.Buttons","global!tinymce.util.Tools.resolve","tinymce.plugins.autosave.core.Storage","global!window","tinymce.core.EditorManager","tinymce.core.util.Tools","tinymce.plugins.autosave.api.Settings","global!setInterval","tinymce.core.util.LocalStorage","tinymce.plugins.autosave.api.Events","global!document","tinymce.plugins.autosave.core.Time"] -jsc*/ -define( - 'ephox.katamari.api.Cell', - - [ - ], - - function () { - var Cell = function (initial) { - var value = initial; - - var get = function () { - return value; - }; - - var set = function (v) { - value = v; - }; - - var clone = function () { - return Cell(get()); - }; - - return { - get: get, - set: set, - clone: clone - }; + var Cell = function (initial) { + var value = initial; + var get = function () { + return value; }; - - return Cell; - } -); - -defineGlobal("global!tinymce.util.Tools.resolve", tinymce.util.Tools.resolve); -/** - * ResolveGlobal.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.core.PluginManager', - [ - 'global!tinymce.util.Tools.resolve' - ], - function (resolve) { - return resolve('tinymce.PluginManager'); - } -); - -defineGlobal("global!setInterval", setInterval); -/** - * ResolveGlobal.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.core.util.LocalStorage', - [ - 'global!tinymce.util.Tools.resolve' - ], - function (resolve) { - return resolve('tinymce.util.LocalStorage'); - } -); - -/** - * ResolveGlobal.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.core.util.Tools', - [ - 'global!tinymce.util.Tools.resolve' - ], - function (resolve) { - return resolve('tinymce.util.Tools'); - } -); - -/** - * Events.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.api.Events', - [ - ], - function () { - var fireRestoreDraft = function (editor) { - return editor.fire('RestoreDraft'); + var set = function (v) { + value = v; }; - - var fireStoreDraft = function (editor) { - return editor.fire('StoreDraft'); + var clone = function () { + return Cell(get()); }; - - var fireRemoveDraft = function (editor) { - return editor.fire('RemoveDraft'); - }; - return { - fireRestoreDraft: fireRestoreDraft, - fireStoreDraft: fireStoreDraft, - fireRemoveDraft: fireRemoveDraft + get: get, + set: set, + clone: clone }; - } -); + }; -defineGlobal("global!document", document); -/** - * Time.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 - */ + var global = tinymce.util.Tools.resolve('tinymce.PluginManager'); -define( - 'tinymce.plugins.autosave.core.Time', - [ - ], - function () { - var parse = function (time, defaultTime) { - var multiples = { - s: 1000, - m: 60000 - }; + var global$1 = tinymce.util.Tools.resolve('tinymce.util.LocalStorage'); - time = /^(\d+)([ms]?)$/.exec('' + (time || defaultTime)); + var global$2 = tinymce.util.Tools.resolve('tinymce.util.Tools'); - return (time[2] ? multiples[time[2]] : 1) * parseInt(time, 10); - }; + var fireRestoreDraft = function (editor) { + return editor.fire('RestoreDraft'); + }; + var fireStoreDraft = function (editor) { + return editor.fire('StoreDraft'); + }; + var fireRemoveDraft = function (editor) { + return editor.fire('RemoveDraft'); + }; + var $_1qssoj9ajm0ofy3g = { + fireRestoreDraft: fireRestoreDraft, + fireStoreDraft: fireStoreDraft, + fireRemoveDraft: fireRemoveDraft + }; - return { - parse: parse + var parse = function (time, defaultTime) { + var multiples = { + s: 1000, + m: 60000 }; - } -); -/** - * Settings.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 - */ + time = /^(\d+)([ms]?)$/.exec('' + (time || defaultTime)); + return (time[2] ? multiples[time[2]] : 1) * parseInt(time, 10); + }; + var $_60wi379cjm0ofy3k = { parse: parse }; -define( - 'tinymce.plugins.autosave.api.Settings', - [ - 'global!document', - 'tinymce.plugins.autosave.core.Time' - ], - function (document, Time) { - var shouldAskBeforeUnload = function (editor) { - return editor.getParam("autosave_ask_before_unload", true); - }; + var shouldAskBeforeUnload = function (editor) { + return editor.getParam('autosave_ask_before_unload', true); + }; + var getAutoSavePrefix = function (editor) { + var prefix = editor.getParam('autosave_prefix', 'tinymce-autosave-{path}{query}{hash}-{id}-'); + prefix = prefix.replace(/\{path\}/g, document.location.pathname); + prefix = prefix.replace(/\{query\}/g, document.location.search); + prefix = prefix.replace(/\{hash\}/g, document.location.hash); + prefix = prefix.replace(/\{id\}/g, editor.id); + return prefix; + }; + var shouldRestoreWhenEmpty = function (editor) { + return editor.getParam('autosave_restore_when_empty', false); + }; + var getAutoSaveInterval = function (editor) { + return $_60wi379cjm0ofy3k.parse(editor.settings.autosave_interval, '30s'); + }; + var getAutoSaveRetention = function (editor) { + return $_60wi379cjm0ofy3k.parse(editor.settings.autosave_retention, '20m'); + }; + var $_azapea9bjm0ofy3i = { + shouldAskBeforeUnload: shouldAskBeforeUnload, + getAutoSavePrefix: getAutoSavePrefix, + shouldRestoreWhenEmpty: shouldRestoreWhenEmpty, + getAutoSaveInterval: getAutoSaveInterval, + getAutoSaveRetention: getAutoSaveRetention + }; - var getAutoSavePrefix = function (editor) { - var prefix = editor.getParam('autosave_prefix', 'tinymce-autosave-{path}{query}{hash}-{id}-'); + var isEmpty = function (editor, html) { + var forcedRootBlockName = editor.settings.forced_root_block; + html = global$2.trim(typeof html === 'undefined' ? editor.getBody().innerHTML : html); + return html === '' || new RegExp('^<' + forcedRootBlockName + '[^>]*>((\xA0|&nbsp;|[ \t]|<br[^>]*>)+?|)</' + forcedRootBlockName + '>|<br>$', 'i').test(html); + }; + var hasDraft = function (editor) { + var time = parseInt(global$1.getItem($_azapea9bjm0ofy3i.getAutoSavePrefix(editor) + 'time'), 10) || 0; + if (new Date().getTime() - time > $_azapea9bjm0ofy3i.getAutoSaveRetention(editor)) { + removeDraft(editor, false); + return false; + } + return true; + }; + var removeDraft = function (editor, fire) { + var prefix = $_azapea9bjm0ofy3i.getAutoSavePrefix(editor); + global$1.removeItem(prefix + 'draft'); + global$1.removeItem(prefix + 'time'); + if (fire !== false) { + $_1qssoj9ajm0ofy3g.fireRemoveDraft(editor); + } + }; + var storeDraft = function (editor) { + var prefix = $_azapea9bjm0ofy3i.getAutoSavePrefix(editor); + if (!isEmpty(editor) && editor.isDirty()) { + global$1.setItem(prefix + 'draft', editor.getContent({ + format: 'raw', + no_events: true + })); + global$1.setItem(prefix + 'time', new Date().getTime().toString()); + $_1qssoj9ajm0ofy3g.fireStoreDraft(editor); + } + }; + var restoreDraft = function (editor) { + var prefix = $_azapea9bjm0ofy3i.getAutoSavePrefix(editor); + if (hasDraft(editor)) { + editor.setContent(global$1.getItem(prefix + 'draft'), { format: 'raw' }); + $_1qssoj9ajm0ofy3g.fireRestoreDraft(editor); + } + }; + var startStoreDraft = function (editor, started) { + var interval = $_azapea9bjm0ofy3i.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(); + }; + var $_8h0aas97jm0ofy3d = { + isEmpty: isEmpty, + hasDraft: hasDraft, + removeDraft: removeDraft, + storeDraft: storeDraft, + restoreDraft: restoreDraft, + startStoreDraft: startStoreDraft, + restoreLastDraft: restoreLastDraft + }; - prefix = prefix.replace(/\{path\}/g, document.location.pathname); - prefix = prefix.replace(/\{query\}/g, document.location.search); - prefix = prefix.replace(/\{hash\}/g, document.location.hash); - prefix = prefix.replace(/\{id\}/g, editor.id); - - return prefix; + var curry = function (f, editor) { + return function () { + var args = Array.prototype.slice.call(arguments); + return f.apply(null, [editor].concat(args)); }; - - var shouldRestoreWhenEmpty = function (editor) { - return editor.getParam('autosave_restore_when_empty', false); - }; - - var getAutoSaveInterval = function (editor) { - return Time.parse(editor.settings.autosave_interval, '30s'); - }; - - var getAutoSaveRetention = function (editor) { - return Time.parse(editor.settings.autosave_retention, '20m'); - }; - + }; + var get = function (editor) { return { - shouldAskBeforeUnload: shouldAskBeforeUnload, - getAutoSavePrefix: getAutoSavePrefix, - shouldRestoreWhenEmpty: shouldRestoreWhenEmpty, - getAutoSaveInterval: getAutoSaveInterval, - getAutoSaveRetention: getAutoSaveRetention + hasDraft: curry($_8h0aas97jm0ofy3d.hasDraft, editor), + storeDraft: curry($_8h0aas97jm0ofy3d.storeDraft, editor), + restoreDraft: curry($_8h0aas97jm0ofy3d.restoreDraft, editor), + removeDraft: curry($_8h0aas97jm0ofy3d.removeDraft, editor), + isEmpty: curry($_8h0aas97jm0ofy3d.isEmpty, editor) }; - } -); -/** - * 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 - */ + }; + var $_7x9aqp96jm0ofy3c = { get: get }; -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; + var global$3 = tinymce.util.Tools.resolve('tinymce.EditorManager'); - 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; + global$3._beforeUnloadHandler = function () { + var msg; + global$2.each(global$3.get(), function (editor) { + if (editor.plugins.autosave) { + editor.plugins.autosave.storeDraft(); } - - 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); + if (!msg && editor.isDirty() && $_azapea9bjm0ofy3i.shouldAskBeforeUnload(editor)) { + msg = editor.translate('You have unsaved changes are you sure you want to navigate away?'); } - }; + }); + return msg; + }; + var setup = function (editor) { + window.onbeforeunload = global$3._beforeUnloadHandler; + }; + var $_6xebc99ejm0ofy43 = { setup: setup }; - 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); + var postRender = function (editor, started) { + return function (e) { + var ctrl = e.control; + ctrl.disabled(!$_8h0aas97jm0ofy3d.hasDraft(editor)); + editor.on('StoreDraft RestoreDraft RemoveDraft', function () { + ctrl.disabled(!$_8h0aas97jm0ofy3d.hasDraft(editor)); }); - - editor.focus(); + $_8h0aas97jm0ofy3d.startStoreDraft(editor, started); }; + }; + var register = function (editor, started) { + editor.addButton('restoredraft', { + title: 'Restore last draft', + onclick: function () { + $_8h0aas97jm0ofy3d.restoreLastDraft(editor); + }, + onPostRender: postRender(editor, started) + }); + editor.addMenuItem('restoredraft', { + text: 'Restore last draft', + onclick: function () { + $_8h0aas97jm0ofy3d.restoreLastDraft(editor); + }, + onPostRender: postRender(editor, started), + context: 'file' + }); + }; + var $_drdg7d9gjm0ofy46 = { register: register }; - return { - isEmpty: isEmpty, - hasDraft: hasDraft, - removeDraft: removeDraft, - storeDraft: storeDraft, - restoreDraft: restoreDraft, - startStoreDraft: startStoreDraft, - restoreLastDraft: restoreLastDraft - }; + global.add('autosave', function (editor) { + var started = Cell(false); + $_6xebc99ejm0ofy43.setup(editor); + $_drdg7d9gjm0ofy46.register(editor, started); + return $_7x9aqp96jm0ofy3c.get(editor); + }); + function Plugin () { } -); -/** - * Api.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.api.Api', - [ - 'tinymce.plugins.autosave.core.Storage' - ], - function (Storage) { - // Inlined the curry function since adding Fun without tree shaking to every plugin would produce a lot of bloat - var curry = function (f, editor) { - return function () { - var args = Array.prototype.slice.call(arguments); - return f.apply(null, [editor].concat(args)); - }; - }; + return Plugin; - var get = function (editor) { - return { - hasDraft: curry(Storage.hasDraft, editor), - storeDraft: curry(Storage.storeDraft, editor), - restoreDraft: curry(Storage.restoreDraft, editor), - removeDraft: curry(Storage.removeDraft, editor), - isEmpty: curry(Storage.isEmpty, editor) - }; - }; - - return { - get: get - }; - } -); -defineGlobal("global!window", window); -/** - * ResolveGlobal.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.core.EditorManager', - [ - 'global!tinymce.util.Tools.resolve' - ], - function (resolve) { - return resolve('tinymce.EditorManager'); - } -); - -/** - * BeforeUnload.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.BeforeUnload', - [ - 'global!window', - 'tinymce.core.EditorManager', - 'tinymce.core.util.Tools', - 'tinymce.plugins.autosave.api.Settings' - ], - function (window, EditorManager, Tools, Settings) { - EditorManager._beforeUnloadHandler = function () { - var msg; - - Tools.each(EditorManager.get(), function (editor) { - // Store a draft for each editor instance - if (editor.plugins.autosave) { - editor.plugins.autosave.storeDraft(); - } - - // Setup a return message if the editor is dirty - if (!msg && editor.isDirty() && Settings.shouldAskBeforeUnload(editor)) { - msg = editor.translate("You have unsaved changes are you sure you want to navigate away?"); - } - }); - - return msg; - }; - - var setup = function (editor) { - window.onbeforeunload = EditorManager._beforeUnloadHandler; - }; - - return { - setup: setup - }; - } -); -/** - * Buttons.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.ui.Buttons', - [ - 'tinymce.plugins.autosave.core.Storage' - ], - function (Storage) { - var postRender = function (editor, started) { - return function (e) { - var ctrl = e.control; - - ctrl.disabled(!Storage.hasDraft(editor)); - - editor.on('StoreDraft RestoreDraft RemoveDraft', function () { - ctrl.disabled(!Storage.hasDraft(editor)); - }); - - // TODO: Investigate why this is only done on postrender that would - // make the feature broken if only the menu item was rendered since - // it is rendered when the menu appears - Storage.startStoreDraft(editor, started); - }; - }; - - var register = function (editor, started) { - editor.addButton('restoredraft', { - title: 'Restore last draft', - onclick: function () { - Storage.restoreLastDraft(editor); - }, - onPostRender: postRender(editor, started) - }); - - editor.addMenuItem('restoredraft', { - text: 'Restore last draft', - onclick: function () { - Storage.restoreLastDraft(editor); - }, - onPostRender: postRender(editor, started), - context: 'file' - }); - }; - - return { - register: register - }; - } -); -/** - * Plugin.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 - */ - -/** - * This class contains all core logic for the autosave plugin. - * - * @class tinymce.autosave.Plugin - * @private - */ -define( - 'tinymce.plugins.autosave.Plugin', - [ - 'ephox.katamari.api.Cell', - 'tinymce.core.PluginManager', - 'tinymce.plugins.autosave.api.Api', - 'tinymce.plugins.autosave.core.BeforeUnload', - 'tinymce.plugins.autosave.ui.Buttons' - ], - function (Cell, PluginManager, Api, BeforeUnload, Buttons) { - PluginManager.add('autosave', function (editor) { - var started = Cell(false); - - BeforeUnload.setup(editor); - Buttons.register(editor, started); - - return Api.get(editor); - }); - - return function () { }; - } -); -dem('tinymce.plugins.autosave.Plugin')(); +}()); })();