芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/chacsinkinyucatan.gob.mx/media/plg_editors_tinymce/js/tinymce.js
/** * @copyright (C) 2018 Open Source Matters, Inc.
* @license GNU General Public License version 2 or later; see LICENSE.txt */ ((tinyMCE, Joomla, window, document) => { Joomla.JoomlaTinyMCE = { /** * Find all TinyMCE elements and initialize TinyMCE instance for each * * @param {HTMLElement} target Target Element where to search for the editor element * * @since 3.7.0 */ setupEditors: target => { const container = target || document; const pluginOptions = Joomla.getOptions ? Joomla.getOptions('plg_editor_tinymce', {}) : Joomla.optionsStorage.plg_editor_tinymce || {}; const editors = [].slice.call(container.querySelectorAll('.js-editor-tinymce')); editors.forEach(editor => { const currentEditor = editor.querySelector('textarea'); const toggleButton = editor.querySelector('.js-tiny-toggler-button'); const toggleIcon = editor.querySelector('.icon-eye'); // Setup the editor Joomla.JoomlaTinyMCE.setupEditor(currentEditor, pluginOptions); // Setup the toggle button if (toggleButton) { toggleButton.removeAttribute('disabled'); toggleButton.addEventListener('click', () => { if (Joomla.editors.instances[currentEditor.id].instance.isHidden()) { toggleIcon.setAttribute('class', 'icon-eye'); Joomla.editors.instances[currentEditor.id].instance.show(); } else { toggleIcon.setAttribute('class', 'icon-eye-slash'); Joomla.editors.instances[currentEditor.id].instance.hide(); } }); } }); }, /** * Initialize TinyMCE editor instance * * @param {HTMLElement} element * @param {Object} pluginOptions * * @since 3.7.0 */ setupEditor: (element, pluginOptions) => { // Check whether the editor already has ben set if (Joomla.editors.instances[element.id]) { return; } const name = element ? element.getAttribute('name').replace(/\[\]|\]/g, '').split('[').pop() : 'default'; // Get Editor name const tinyMCEOptions = pluginOptions ? pluginOptions.tinyMCE || {} : {}; const defaultOptions = tinyMCEOptions.default || {}; // Check specific options by the name let options = tinyMCEOptions[name] ? tinyMCEOptions[name] : defaultOptions; // Avoid an unexpected changes, and copy the options object if (options.joomlaMergeDefaults) { options = Joomla.extend(Joomla.extend({}, defaultOptions), options); } else { options = Joomla.extend({}, options); } if (element) { // We already have the Target, so reset the selector and assign given element as target options.selector = null; options.target = element; } const buttonValues = []; const arr = Object.keys(options.joomlaExtButtons.names).map(key => options.joomlaExtButtons.names[key]); const icons = { joomla: '
' }; arr.forEach(xtdButton => { const tmp = {}; tmp.text = xtdButton.name; tmp.icon = xtdButton.icon; tmp.type = 'menuitem'; if (xtdButton.iconSVG) { icons[tmp.icon] = xtdButton.iconSVG; } if (xtdButton.href) { tmp.onAction = () => { document.getElementById(`${xtdButton.id}_modal`).open(); }; } else { tmp.onAction = () => { // eslint-disable-next-line no-new-func new Function(xtdButton.click)(); }; } buttonValues.push(tmp); }); // Ensure tinymce is initialised in readonly mode if the textarea has readonly applied let readOnlyMode = false; if (element) { readOnlyMode = element.readOnly; } if (buttonValues.length) { options.setup = editor => { editor.settings.readonly = readOnlyMode; Object.keys(icons).forEach(icon => { editor.ui.registry.addIcon(icon, icons[icon]); }); editor.ui.registry.addMenuButton('jxtdbuttons', { text: Joomla.Text._('PLG_TINY_CORE_BUTTONS'), icon: 'joomla', fetch: callback => callback(buttonValues) }); }; } else { options.setup = editor => { editor.settings.readonly = readOnlyMode; }; } // We'll take over the onSubmit event options.init_instance_callback = editor => { editor.on('submit', () => { if (editor.isHidden()) { editor.show(); } }, true); }; // Create a new instance // eslint-disable-next-line no-undef const ed = new tinyMCE.Editor(element.id, options, tinymce.EditorManager); ed.render(); /** Register the editor's instance to Joomla Object */ Joomla.editors.instances[element.id] = { // Required by Joomla's API for the XTD-Buttons getValue: () => Joomla.editors.instances[element.id].instance.getContent(), setValue: text => Joomla.editors.instances[element.id].instance.setContent(text), getSelection: () => Joomla.editors.instances[element.id].instance.selection.getContent({ format: 'text' }), replaceSelection: text => Joomla.editors.instances[element.id].instance.execCommand('mceInsertContent', false, text), // Required by Joomla's API for Mail Component Integration disable: disabled => Joomla.editors.instances[element.id].instance.setMode(disabled ? 'readonly' : 'design'), // Some extra instance dependent id: element.id, instance: ed }; } }; /** * Initialize at an initial page load */ document.addEventListener('DOMContentLoaded', () => { Joomla.JoomlaTinyMCE.setupEditors(document); }); /** * Initialize when a part of the page was updated */ document.addEventListener('joomla:updated', ({ target }) => Joomla.JoomlaTinyMCE.setupEditors(target)); })(window.tinyMCE, Joomla, window, document);