Skip to content

Commit

Permalink
add tinymace plugin, T-17631
Browse files Browse the repository at this point in the history
  • Loading branch information
Tumppex committed Oct 4, 2024
1 parent 9457884 commit e6b3247
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions assets/js/plugin-tinymce-add-class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable no-undef, no-unused-vars */
(function addClassesToWysiwygElements() {
tinymce.create('tinymce.plugins.addClass', {
init(editor, url) {
editor.on('NodeChange', () => {
const elements = editor.dom.select('ul, ol, blockquote');

elements.forEach((element) => {
if (!editor.dom.hasClass(element, 'wysiwyg')) {
editor.dom.addClass(element, 'wysiwyg');
}
});
});
},
});

tinymce.PluginManager.add('addClass', tinymce.plugins.addClass);
}());
14 changes: 14 additions & 0 deletions inc/tinymce.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,17 @@ function air_helper_tinymce_remove_formats( $init ) {
$init['block_formats'] = 'Paragraph=p;Heading 2=h2;Heading 3=h3;Heading 4=h4;';
return $init;
} // end air_helper_tinymce_remove_formats

/**
* Add helper class to specific elements in TinyMCE
*/
function add_tinymce_plugin( $plugin_array ) {
$plugin_array['addClass'] = air_helper_base_url() . '/assets/js/plugin-tinymce-add-class.js';
return $plugin_array;
}

function tinymce_plugin() {
add_filter( 'mce_external_plugins', 'add_tinymce_plugin' );
}

add_action( 'admin_head', 'tinymce_plugin' );

0 comments on commit e6b3247

Please sign in to comment.