Align content to rtl in tinymce using jquery

I’m Developing a WordPress plugin and i added a button to tinymce interface, when user press it the direction of the text convert from right to left .
i tried to do the following but with no luck

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

enter image description here

Related posts

Leave a Reply

2 comments

  1. The Codex article about Writing a Post in RTL Language recommends the use of the plugin WP-RTL, which

    […] enables the text directions functionality that exist already in the original TinyMCE editor which allow writing texts in Left-to-Right and Right-to-Left directions in the same post (or page) for languages like Arabic, Persian and Hebrew.

    Its code is dead simple:

    <?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 this is what it does:

  2. It would seem that there is already a plugin that you can initialize that deals with directionality in TinyMCE here

    Is this what your looking for or am I missing something?

    PS: its not clear as to whether or not it works within the editor, So it may not, but It’s worth a shot I think if it sounds like what your looking for.