Skip to content

Commit

Permalink
Issue #1: Switch TinyMCE plugin to IIFE
Browse files Browse the repository at this point in the history
  • Loading branch information
indigoxela committed Dec 18, 2023
1 parent 05fb674 commit 01e3fa7
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions js/plugins/paraafter/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,40 @@
* @file
* TinyMCE paragraph after plugin.
*/
"use strict";
(function () {

tinymce.PluginManager.add('paraafter', function (editor, url) {
editor.ui.registry.addButton('paraafter', {
icon: 'paraafter',
tooltip: editor.options.get('paraafterTooltip'),
onAction: function (api) {
paraafterTools.insert(editor);
}
});
'use strict';

editor.ui.registry.addMenuItem('paraafter', {
icon: 'paraafter',
text: editor.options.get('paraafterTooltip'),
onAction: function (api) {
paraafterTools.insert(editor);
const paraafterInsert = function (editor) {
let node = editor.selection.getNode();
let parent = node;
while (node = node.parentNode) {
if (node.nodeName == 'BODY') {
break;
}
parent = node;
}
});
});
let p = editor.dom.create('p', {}, ' ');
editor.dom.insertAfter(p, parent);
editor.selection.setCursorLocation(p, 0);
}

const paraafterTools = {}
tinymce.PluginManager.add('paraafter', function (editor, url) {
editor.ui.registry.addButton('paraafter', {
icon: 'paraafter',
tooltip: editor.options.get('paraafterTooltip'),
onAction: function (api) {
paraafterInsert(editor);
}
});

paraafterTools.insert = function (editor) {
let node = editor.selection.getNode();
let parent = node;
while (node = node.parentNode) {
if (node.nodeName == 'BODY') {
break;
}
parent = node;
}
let p = editor.dom.create('p', {}, ' ');
editor.dom.insertAfter(p, parent);
editor.selection.setCursorLocation(p, 0);
}
editor.ui.registry.addMenuItem('paraafter', {
icon: 'paraafter',
text: editor.options.get('paraafterTooltip'),
onAction: function (api) {
paraafterInsert(editor);
}
});
});

})();

0 comments on commit 01e3fa7

Please sign in to comment.