I need to insert some text in the body of the article, that turns into a "side-tag" by wrapping it inside some div tags with custom classes.
I've created a custom button in tinymce that pops up a new window with a text field. You write the text and when you hit OK it adds the beginning and endig div tags and inserts it into the wp editor where your cursor was.
Here is the code:
(function () {
tinymce.PluginManager.add('custom_mce_button2', function(editor, url) {
editor.addButton('custom_mce_button2', {
icon: false,
text: 'Side Tag',
onclick: function (e) {
editor.windowManager.open( {
title: 'Insert a Sidetag',
body: [{
type: 'textbox',
name: 'title',
placeholder: 'Type the side tag content here.',
multiline: true,
minWidth: 700,
minHeight: 50,
},
{
type: 'button',
name: 'link',
text: 'Insert/Edit link',
onclick: function( e ) {
//get the Wordpess' "Insert/edit link" popup window.
},
}],
onsubmit: function( e ) {
editor.insertContent( '<div class="side-tag-wrap hidden-xs"><div class="side-tag">' + e.data.title + '</div></div>');
}
});
}
});
});
})();
And what it does:
So far everything works but... I also want to be able to add links while the popup window is still on, exactly how the "Insert/Edit link" button of the default editor works. I know how to use the link plugin of tinymce but this doesn't help. I mainly want to link posts that are already published so I need this:
Is there a way to call this button in my custom popup window or call the quicktags function ?