Redactor / Documentation / API

Core

object #

Getting Redactor object.

var redactor = $('#content').redactor('core.object');

When using in plugins, Redactor object can be accessed using 'this'

editor #

Accessing editable layer.

var editor = $('#content').redactor('core.editor');

box #

Accessing container element, that contains editable layer and textarea.

var box = $('#content').redactor('core.box');

textarea #

Accessing textarea. In case Redactor has been applied to textarea element, core.textarea() will return this element. Otherwise Redactor will create its own textarea and return it.

Redactor always writes the final code to textarea. Editable layer, however, may contain temporary tags for proper visual representation of the text and for formatting purposes. Textarea code doesn't contain any of these temporary tags.

var textarea = $('#content').redactor('core.textarea');

toolbar #

Accessing toolbar element.

var toolbar = $('#content').redactor('core.toolbar');

callback #

Setting callback for functions. This method only works with plugins, and doesn't properly respond to external calls.

In plugins it can be called this way:

this.core.callback('my', e, data);

Arguments:

  • 'my' — callback name. Callback prefix will be added automatically to the name, resulting in name like this: 'myCallback'
  • e — event object (optional)
  • data — any data, object or function (optional)

If there's no need to pass an event object, it can be dropped from the arguments:

this.core.callback('my', data);

Now callback can be called on launch of Redactor:

$('#content').redactor({
    callbacks: {
	    my: function(e, data)
        {
            // your code
		}
    }
});

Or, if you didn't pass event object in arguments:

$('#content').redactor({
    callbacks: {
	    my: function(data)
        {
            // your code
		}
    }
});

Or, if you didn't pass any arguments:

$('#content').redactor({
    callbacks: {
	    my: function()
        {
            // your code
		}
    }
});

Redactor object is always available inside of a callback via 'this'. It allows to call any Redactor function or variable, for example:

$('#content').redactor({
    callbacks: {
	    my: function(e, data)
        {
            console.log(this.code.get());
		}
    }	
});

destroy #

Turn Redactor off.

$('#content').redactor('core.destroy');

To call from a plugin:

this.core.destroy();

id #

Accessing element ID.

var id = $('#content').redactor('core.id');

air #

Accessing air toolbar element.

var air = $('#content').redactor('core.air');

element #

This method returns jQuery object over which Redactor has been initialized.

var $el = this.core.element();