Skip to content

Instantly share code, notes, and snippets.

@jpneey
Created August 15, 2023 08:56
Show Gist options
  • Save jpneey/8ebbc654d459c46922276b7816ce2f64 to your computer and use it in GitHub Desktop.
Save jpneey/8ebbc654d459c46922276b7816ce2f64 to your computer and use it in GitHub Desktop.
Button plugin for Tiny MCE
(function() {
tinymce.PluginManager.add('echo_mce_button', function( editor, url ) {
editor.addButton( 'echo_mce_button', {
text: 'Add button',
icon: false,
classes: "echo-mce-button",
onclick: function() {
editor.windowManager.open( {
title: 'Add a button',
body: [
{
type: 'textbox',
name: 'label',
label: 'Button Label',
value: 'Read More'
},
{
type: 'textbox',
name: 'url',
label: 'Button Link',
value: 'https://www.example.com/'
},
{
type: 'listbox',
name: 'classname',
label: 'Button style',
'values': [
{text: 'Primary button', value: 'button'},
{text: 'Secondary button', value: 'button-alt'},
]
},
{
type: 'listbox',
name: 'target',
label: 'Target',
'values': [
{text: 'Default', value: ''},
{text: 'New tab', value: '_blank'},
]
}
],
onsubmit: function( e ) {
editor.insertContent( '<a href="'+ e.data.url +'" class="'+ e.data.classname +'" target="'+ e.data.target +'">'+ e.data.label +'</a>');
console.log( editor )
console.log( e )
// editor.focus();
}
});
}
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment