/*! * 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.7.0 (2021-02-10) * */ !function(n){var r={};function a(e){if(r[e])return r[e].exports;var t=r[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,a),t.l=!0,t.exports}a.m=n,a.c=r,a.d=function(e,t,n){a.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},a.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},a.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s="./src/js/plugins/insertdatetime/plugin.js")}({"./src/js/plugins/insertdatetime/plugin.js":function(module,exports){eval("/**\n * Copyright (c) Tiny Technologies, Inc. All rights reserved.\n * Licensed under the LGPL or a commercial license.\n * For LGPL see License.txt in the project root for license information.\n * For commercial licenses see https://www.tiny.cloud/\n *\n * Version: 5.7.0 (2021-02-10)\n */\n (function () {\n 'use strict';\n\n var global = tinymce.util.Tools.resolve('tinymce.PluginManager');\n\n var getDateFormat = function (editor) {\n return editor.getParam('insertdatetime_dateformat', editor.translate('%Y-%m-%d'));\n };\n var getTimeFormat = function (editor) {\n return editor.getParam('insertdatetime_timeformat', editor.translate('%H:%M:%S'));\n };\n var getFormats = function (editor) {\n return editor.getParam('insertdatetime_formats', [\n '%H:%M:%S',\n '%Y-%m-%d',\n '%I:%M:%S %p',\n '%D'\n ]);\n };\n var getDefaultDateTime = function (editor) {\n var formats = getFormats(editor);\n return formats.length > 0 ? formats[0] : getTimeFormat(editor);\n };\n var shouldInsertTimeElement = function (editor) {\n return editor.getParam('insertdatetime_element', false);\n };\n\n var daysShort = 'Sun Mon Tue Wed Thu Fri Sat Sun'.split(' ');\n var daysLong = 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sunday'.split(' ');\n var monthsShort = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ');\n var monthsLong = 'January February March April May June July August September October November December'.split(' ');\n var addZeros = function (value, len) {\n value = '' + value;\n if (value.length < len) {\n for (var i = 0; i < len - value.length; i++) {\n value = '0' + value;\n }\n }\n return value;\n };\n var getDateTime = function (editor, fmt, date) {\n date = date || new Date();\n fmt = fmt.replace('%D', '%m/%d/%Y');\n fmt = fmt.replace('%r', '%I:%M:%S %p');\n fmt = fmt.replace('%Y', '' + date.getFullYear());\n fmt = fmt.replace('%y', '' + date.getYear());\n fmt = fmt.replace('%m', addZeros(date.getMonth() + 1, 2));\n fmt = fmt.replace('%d', addZeros(date.getDate(), 2));\n fmt = fmt.replace('%H', '' + addZeros(date.getHours(), 2));\n fmt = fmt.replace('%M', '' + addZeros(date.getMinutes(), 2));\n fmt = fmt.replace('%S', '' + addZeros(date.getSeconds(), 2));\n fmt = fmt.replace('%I', '' + ((date.getHours() + 11) % 12 + 1));\n fmt = fmt.replace('%p', '' + (date.getHours() < 12 ? 'AM' : 'PM'));\n fmt = fmt.replace('%B', '' + editor.translate(monthsLong[date.getMonth()]));\n fmt = fmt.replace('%b', '' + editor.translate(monthsShort[date.getMonth()]));\n fmt = fmt.replace('%A', '' + editor.translate(daysLong[date.getDay()]));\n fmt = fmt.replace('%a', '' + editor.translate(daysShort[date.getDay()]));\n fmt = fmt.replace('%%', '%');\n return fmt;\n };\n var updateElement = function (editor, timeElm, computerTime, userTime) {\n var newTimeElm = editor.dom.create('time', { datetime: computerTime }, userTime);\n timeElm.parentNode.insertBefore(newTimeElm, timeElm);\n editor.dom.remove(timeElm);\n editor.selection.select(newTimeElm, true);\n editor.selection.collapse(false);\n };\n var insertDateTime = function (editor, format) {\n if (shouldInsertTimeElement(editor)) {\n var userTime = getDateTime(editor, format);\n var computerTime = void 0;\n if (/%[HMSIp]/.test(format)) {\n computerTime = getDateTime(editor, '%Y-%m-%dT%H:%M');\n } else {\n computerTime = getDateTime(editor, '%Y-%m-%d');\n }\n var timeElm = editor.dom.getParent(editor.selection.getStart(), 'time');\n if (timeElm) {\n updateElement(editor, timeElm, computerTime, userTime);\n } else {\n editor.insertContent('');\n }\n } else {\n editor.insertContent(getDateTime(editor, format));\n }\n };\n\n var register = function (editor) {\n editor.addCommand('mceInsertDate', function () {\n insertDateTime(editor, getDateFormat(editor));\n });\n editor.addCommand('mceInsertTime', function () {\n insertDateTime(editor, getTimeFormat(editor));\n });\n };\n\n var Cell = function (initial) {\n var value = initial;\n var get = function () {\n return value;\n };\n var set = function (v) {\n value = v;\n };\n return {\n get: get,\n set: set\n };\n };\n\n var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');\n\n var register$1 = function (editor) {\n var formats = getFormats(editor);\n var defaultFormat = Cell(getDefaultDateTime(editor));\n editor.ui.registry.addSplitButton('insertdatetime', {\n icon: 'insert-time',\n tooltip: 'Insert date/time',\n select: function (value) {\n return value === defaultFormat.get();\n },\n fetch: function (done) {\n done(global$1.map(formats, function (format) {\n return {\n type: 'choiceitem',\n text: getDateTime(editor, format),\n value: format\n };\n }));\n },\n onAction: function (_api) {\n insertDateTime(editor, defaultFormat.get());\n },\n onItemAction: function (_api, value) {\n defaultFormat.set(value);\n insertDateTime(editor, value);\n }\n });\n var makeMenuItemHandler = function (format) {\n return function () {\n defaultFormat.set(format);\n insertDateTime(editor, format);\n };\n };\n editor.ui.registry.addNestedMenuItem('insertdatetime', {\n icon: 'insert-time',\n text: 'Date/time',\n getSubmenuItems: function () {\n return global$1.map(formats, function (format) {\n return {\n type: 'menuitem',\n text: getDateTime(editor, format),\n onAction: makeMenuItemHandler(format)\n };\n });\n }\n });\n };\n\n function Plugin () {\n global.add('insertdatetime', function (editor) {\n register(editor);\n register$1(editor);\n });\n }\n\n Plugin();\n\n}());\n\n\n//# sourceURL=webpack:///./src/js/plugins/insertdatetime/plugin.js?")}});