Created
September 22, 2020 15:25
-
-
Save smailliwcs/3919548a04b7677893bbdba25016d235 to your computer and use it in GitHub Desktop.
TinyMCE plugin: columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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