Documentation

Working with settings

Setting options

Options are set as an object when you initialize Redactor.

$R('#content', { breakline: true });

Or if you call Redactor with jQuery:

$('#content').redactor({ breakline: true });

You can set more than one option:

$R('#content', { breakline: true, lang: 'fi' });

Setting options with data attributes

If the HTML element has data attributes, then all of them become options, when you initialize Redactor, for example:

// HTML
<textarea id="content" data-breakline="true" data-lang="fi"></textarea>

// JS
'$R('#content');

In this case, Redactor gets the options from the data attributes and, in the end, the options object {breakline: true, lang: 'fi'}) will be passed automatically.

You can combine the setting options in the initialization and via data attributes.

// HTML
<textarea id="content" data-breakline="true"></textarea>

// JS
'$R('#content', { lang: 'fi' });

In this case, Redactor gets the same options object as in the example above, i,e.: { breakline: true, lang: 'fi' }).

If you initialize Redactor automatically using the attribute data-redactor, all the options will be obtained from the data attributes.

<textarea data-redactor data-breakline="true" data-lang="fi"></textarea>

In this case, Redactor will be launched automatically by the window.load event and will receive the option object as: { breakline: true, lang: 'fi' }).

Global options

If you have several Redactors are running on the page, sometimes in addition to the specific options for each one, you need to set global options for all editors at once. It can be done through the $ R.options object before initialization:

// Global settings
$R.options = {
    lang: 'fi'
};

// Init
$R('#content-1');
$R('#content-2', { breakline: true });

Now, each Redactor will get the language option lang: 'fi' at initialization, in addition to the specific options.

Access to options from plugin

You can use Redactor's options in your plugins. To do it declare the options object in the plugin's constructor and then you can use it as this.opts in plugin's methods.

(function($R)
{
    $R.Plugin.Myplugin = function(app)
    {
        this.app = app;

        // declare options
        this.opts = app.opts;
    };

    $R.Plugin.Myplugin.prototype = {
        start: function()
        {
       // use options
            console.log('lang options is: ', this.opts.lang);
        }
    };
})(Redactor);