Aligning content in rtl in tinymce with jquery

I am developing a Wordpress plugin, and I added a button for the tinymce interface when the user clicks on it text to convert text from right to left. I tried to do the following but no luck

tinymce.get('#tinymce').getBody().dir ="rtl"; 

enter image description here

+6
source share
2 answers

Codex Article on Writing a Message in RTL Recommends Using the WP-RTL Plugin

[...] allows you to use the functionality of text indications that already exist in the original TinyMCE editor, which allow you to write texts from left to right and right to left in the same message (or page) for languages ​​such as Arabic, Persian and Hebrew.

His code is dead simply:

 <?php /* Plugin Name: WP-RTL Plugin URI: http://www.fadvisor.net/blog/2008/10/wp-rtl/ Description: Adds two buttons to the TinyMCE editor to enable writing text in Left to Right (LTR) and Right to Left (RTL) directions. Version: 0.3 Author: Fahad Alduraibi Author URI: http://www.fadvisor.net/blog/ */ add_action( "init", "tinymce_bidi_addbuttons" ); function tinymce_bidi_addbuttons() { if( !current_user_can ( 'edit_posts' ) && !current_user_can ( 'edit_pages' ) ) { return; } if( get_user_option ( 'rich_editing' ) == 'true' ) { add_filter( "mce_external_plugins", "tinymce_bidi_plugin" ); add_filter( "mce_buttons", "tinymce_bidi_buttons" ); } } function tinymce_bidi_buttons($buttons) { array_push($buttons, "separator", "ltr", "rtl"); return $buttons; } function tinymce_bidi_plugin($plugin_array) { if (get_bloginfo('version') < 3.9) { $plugin_array['directionality'] = includes_url('js/tinymce/plugins/directionality/editor_plugin.js'); } else { $plugin_array['directionality'] = includes_url('js/tinymce/plugins/directionality/plugin.min.js'); } return $plugin_array; } 

And here is what he does:


VPgoZ.png

+3
source

It would seem that there is already a plugin that you can initialize when dealing with directivity in TinyMCE here

Is this what you are looking for or am I missing something?

PS: its not clear if it works inside the editor, so that may not be the case, but it is worth what I think if it sounds like what you are looking for.

+2
source

Source: https://habr.com/ru/post/976076/


All Articles