Hey, there! Look at our new WYSIWYG editor.

file.uploaded #

Arguments
file Objectobject of uploaded file
response ObjectJSON object with data from upload script

Triggered on successful file upload (including via drag and drop).

$R('#content', {
        fileUpload: '/myadmin/files/upload/',
    callbacks: {
        file: {
            uploaded: function(file, response)
            {
                // ...
            }
        }
    }
});

Listen to the message in a plugin:

(function($R)
{
    $R.add('plugin', 'myplugin', {
        init: function(app)
        {
            // define app
            this.app = app;
        },

        // messages
        onfile: {
            uploaded: function(file, response)
            {
                // ...
            }
        }
    });
})(Redactor);

Upload script forms a JSON string:

{
    "url": "/files/myfile.pdf",
    "name": "My PDF file",
    "id": 1
}

JSON may contain any data, however, url are required.

file.appended #

Arguments
file Objectobject of uploaded file
response ObjectJSON object with data from upload script

Triggered when on successful file append to the attachment area.

$R('#content', {
        fileUpload: '/myadmin/files/upload/',
        fileAttachment: '#file-target',
    callbacks: {
        file: {
            appended: function(file, response)
            {
                // ...
            }
        }
    }
});

Listen to the message in a plugin:

(function($R)
{
    $R.add('plugin', 'myplugin', {
        init: function(app)
        {
            // define app
            this.app = app;
        },

        // messages
        onfile: {
            appended: function(file, response)
            {
                // ...
            }
        }
    });
})(Redactor);

Upload script forms a JSON string:

{
    "url": "/files/myfile.pdf",
    "name": "My PDF file",
    "id": 1
}

JSON may contain any data, however, url are required.

file.uploadError #

Arguments
response ObjectJSON object with error data

Triggered whenever there is an error in file upload. JSON example:

{
    "error": true,
    "message": "Something went wrong..."
}

Callback example:

$R('#content', {
        fileUpload: '/myadmin/files/upload/',
    callbacks: {
        file: {
            uploadError: function(response)
            {
                alert(response.message);
            }
        }
    }
});

Listen to the message in a plugin:

(function($R)
{
    $R.add('plugin', 'myplugin', {
        init: function(app)
        {
            // define app
            this.app = app;
        },

        // messages
        onfile: {
            uploadError: function(response)
            {
                alert(response.message);
            }
        }
    });
})(Redactor);

file.delete #

Arguments
file Objectobject of the file to be deleted

Triggered before the file will be deleted. This callback allows you to prevent file deletion if you return false.

$R('#content', {
    callbacks: {
        file: {
        delete: function(file)
            {
                 if (some_condition)
                 {
                        // success
                        return true;
                  }
                  else
                   {
                      // fail
                     return false;
                    }
            }
      }
      }
});

Listen to the message in a plugin:

(function($R)
{
    $R.add('plugin', 'myplugin', {
        init: function(app)
        {
            // define app
            this.app = app;
        },

        // messages
        onfile: {
            delete: function(file)
            {
                 if (some_condition)
                 {
                        // success
                        return true;
                  }
                  else
                   {
                      // fail
                     return false;
                    }
            }
        }
    });
})(Redactor);

file.deleted #

Arguments
file Objectobject of deleted file

Triggered when the file is deleted.

$R('#content', {
        fileUpload: '/myadmin/files/upload/',
    callbacks: {
        file: {
            deleted: function(file)
            {
                // ...
            }
        }
    }
});

Listen to the message in a plugin:

(function($R)
{
    $R.add('plugin', 'myplugin', {
        init: function(app)
        {
            // define app
            this.app = app;
        },

        // messages
        onfile: {
            deleted: function(file)
            {
                // ...
            }
        }
    });
})(Redactor);

file.inserted #

Arguments
file Object file object

Triggered when the file is inserted to Redactor with Insertion service API.

$R('#content', {
    callbacks: {
        file: {
            inserted: function(file)
            {
                // ...
            }
        }
    }
});

Listen to the message in a plugin:

(function($R)
{
    $R.add('plugin', 'myplugin', {
        init: function(app)
        {
            // define app
            this.app = app;
        },

        // messages
        onfile: {
            inserted: function(file)
            {
                // ...
            }
        }
    });
})(Redactor);