Days
Hours
Minutes
Seconds
x

New Froala Editor v5.0.0 is here โ€“ Learn More

Skip to content
Froala Documentation

Language

RTL LTR Direction Buttons

Try it yourself:


To change the toolbar's direction the direction option should be used.

Edit in JSFiddle

HTML

<div id="froala-editor">
  <p>Custom buttons for rtl and ltr.</p>
</div>

JAVASCRIPT

<script>
  var changeDirection = function (dir, align) {
    // Wrap block tags.
    this.selection.save();
    this.html.wrap(true, true, true, true);
    this.selection.restore();

    // Get blocks.
    var elements = this.selection.blocks();

    // Save selection to restore it later.
    this.selection.save();

    for (var i = 0; i < elements.length; i++) {
      var element = elements[i];
      if (element != this.el) {
        this.$(element)
          .css('direction', dir)
          .css('text-align', align)
          .removeClass('fr-temp-div');
      }
    }

    // Unwrap temp divs.
    this.html.unwrap();

    // Restore selection.
    this.selection.restore();
  }

  FroalaEditor.DefineIcon('rightToLeft', {NAME: 'long-arrow-left'});
  FroalaEditor.RegisterCommand('rightToLeft', {
    title: 'RTL',
    focus: true,
    undo: true,
    refreshAfterCallback: true,
    callback: function () {
      changeDirection.apply(this, ['rtl', 'right']);
    }
  })

  FroalaEditor.DefineIcon('leftToRight', {NAME: 'long-arrow-right'});
  FroalaEditor.RegisterCommand('leftToRight', {
    title: 'LTR',
    focus: true,
    undo: true,
    refreshAfterCallback: true,
    callback: function () {
      changeDirection.apply(this, ['ltr', 'left']);
    }
  })

  new FroalaEditor('div#froala-editor', {
    // Set custom buttons with separator between them. Also include the name
    // of the buttons  defined in customButtons.
    toolbarButtons: ['undo', 'redo' , 'bold', 'formatOL', 'formatUL', '|', 'rightToLeft', 'leftToRight'],
  })
</script>
Sign up

Download the code by signing up for our newsletter

Sign up

Download the code by signing up for our newsletter

Note: By registering, you confirm that you agree to the processing of your personal data by Froala, Inc. - Froala as described in the Privacy Statement. Froala, Inc. - Froala is part of the Idera group and may share your information with its parent company Idera, Inc., and its affiliates. For further details on how your data is used, stored, and shared, please review our Privacy Statement.