Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* global tinymce */
(function() {
const columnsTinyMCEButton = (function(){
return function(tinyMCE) {
tinyMCE.PluginManager.add( 'columns', function( editor, url ) {
// Add Button to Visual Editor Toolbar
editor.addButton('columns', {
title: 'Insert Column',
cmd: 'columns',
image: url + '/columns.jpg',
});
editor.addCommand('columns', function() {
var selected_text = editor.selection.getContent({
'format': 'html'
});
if ( selected_text.length === 0 ) {
alert( 'Please select some text.' );
return;
}
var open_column = '<div class="column">';
var close_column = '</div>';
var return_text = '';
return_text = open_column + selected_text + close_column;
editor.execCommand('mceReplaceContent', false, return_text);
return;
});
});
};
})();
if (typeof tinymce !== 'undefined') {
columnsTinyMCEButton(tinymce);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment