Skip to content

Instantly share code, notes, and snippets.

@smailliwcs
Created September 22, 2020 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smailliwcs/8aaaa1324b02d97f5cb7091d14b9fc88 to your computer and use it in GitHub Desktop.
Save smailliwcs/8aaaa1324b02d97f5cb7091d14b9fc88 to your computer and use it in GitHub Desktop.
TinyMCE plugin: paragraphs
tinymce.PluginManager.add("paragraphs", function (editor) {
function insert(place) {
var body = editor.getBody();
var paragraph = editor.dom.create("p");
place(paragraph, body);
editor.selection.setCursorLocation(paragraph);
editor.nodeChanged();
}
editor.addMenuItem("paragraph", {
text: "Insert paragraph",
context: "insert",
menu: [
{
text: "At top",
onclick: function () {
insert(function (paragraph, body) {
body.insertBefore(paragraph, body.firstChild);
});
}
},
{
text: "At bottom",
onclick: function () {
insert(function (paragraph, body) {
body.appendChild(paragraph);
});
}
}
]
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment