TinyMCE 4 Problems – Missing classes and how to render HTML
-
I’m working on converting my plugin, Better Font Awesome, to work with WP 3.9 and TinyMCE 4. I’m almost done converting my custom TinyMCE plugin for use with version 4 (it worked fine with v3*), however there are a few questions I have:
1. Previously, I was able to render HTML inside of the list box component I was rendering, which is important because I’m generating a drop down (list box) with a bunch of Font Awesome icons, and I need to be able to actually render the
<i class="fa fa-flag"></i>
bit. This was working before:
https://ps.w.org/better-font-awesome/assets/screenshot-2.png?rev=887838But now the
<i>
elements seem to be getting rendered as plain text, not actual HTML:
https://imgur.com/ax3ELhr2. The second issue is that the unique ID/classes that were attached to my TinyMCE drop-down previously, are now totally gone. The generic TinyMCE classes (e.g.
mce-widget mce-btn mce-menubtn mce-fixed-width mce-listbox mce-last
), and even an ID (mce_16
) are applied to my dropdown, however none of these can be relied on for consistent styling on different WP installs (other users might have more TinyMCE plugins installed that would change the ID count and/ormce-last
class). So I’m trying to figure out if there is any way to add a unique and consistent class to the TinyMCE drop-downI’m creating.Any help would be much appreciate! here’s the code I’m using in my TinyMCE plugin:
( function() { "use strict"; var icons = bfa_vars.fa_icons.split(','); var prefix = bfa_vars.fa_prefix; var icon_i = function(id) { return '<i class="fa ' + prefix + 'fw ' + prefix + id + '"></i>'; } var icon_shortcode = function(id) { return '[icon name="' + id + '" class=""]'; } var bfaSelect = function( editor, url ) { editor.addButton('bfaSelect', function() { var values = []; for (var i = 0; i < icons.length; i++) { var _id = icons[i]; values.push({text: icon_i(_id) + ' ' + _id, value: _id}); } return { type: 'listbox', name: 'bfaSelect', tooltip: 'Better Font Awesome Icons', role: 'bfaSelect', text: 'Icons', label: 'Select :', fixedWidth: true, onselect: function(e) { if (e) { editor.insertContent(icon_shortcode(e.control.settings.value)); } return false; }, values: values, }; }); console.log(editor); }; tinymce.PluginManager.add( 'bfa_plugin', bfaSelect ); } )();
- The topic ‘TinyMCE 4 Problems – Missing classes and how to render HTML’ is closed to new replies.