Created
August 30, 2018 14:19
-
-
Save dingo-d/e5bb742a797e5aefe506303cd260ea99 to your computer and use it in GitHub Desktop.
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
/* 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