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/3919548a04b7677893bbdba25016d235 to your computer and use it in GitHub Desktop.
Save smailliwcs/3919548a04b7677893bbdba25016d235 to your computer and use it in GitHub Desktop.
TinyMCE plugin: columns
tinymce.PluginManager.add("columns", function (editor) {
function insert(count) {
editor.undoManager.transact(function () {
var row = editor.dom.create("div", { "class": "row" });
var width = Math.ceil(12 / count);
for (var index = 0; index < count; index++) {
var column = editor.dom.add(row, "div", { "class": "col-sm-" + width });
editor.dom.add(column, "p", {}, "Column " + (index + 1));
}
var node = editor.selection.getNode();
if (node === editor.getBody()) {
node = node.firstChild;
}
node.parentNode.insertBefore(row, node);
});
}
function getMenuItem(text, count) {
return {
text: text,
onclick: function () {
insert(count);
}
};
}
var menu = [
getMenuItem("Two", 2),
getMenuItem("Three", 3),
getMenuItem("Four", 4)
];
editor.addMenuItem("columns", {
text: "Insert columns",
context: "insert",
menu: menu
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment