user3142695
user3142695

Reputation: 17352

Script for redactor.js doesn't work

I try to create a simple test-Script in Jsfiddle for a external Script (redactor.js), but it doesn't work :-(

if (typeof RedactorPlugins === 'undefined') var RedactorPlugins = {};

RedactorPlugins.advanced = {
    init: function () {
        alert(1);
    }
}

$('#article').redactor({
    plugins: ['advanced']
});

JSFiddle: http://jsfiddle.net/DEYx7/ I don't get the alert...

But I don't know, what I'm doing wrong, cause that is a quite simple example and it should work...

The Example-Code of the external redactor.js-Script: http://imperavi.com/redactor/docs/plugins-creating/

Upvotes: 3

Views: 2335

Answers (1)

muffel
muffel

Reputation: 7390

You need to define your plugin first, and make the plugin object globally available. Please see the updated JSFiddle:

if (typeof RedactorPlugins === 'undefined') window.RedactorPlugins = {};

RedactorPlugins.advanced = {
    init: function () {
        alert(1);
    }
}
$.getScript("http://imperavi.com/js/redactor/redactor.js",function(){
    $('#article').redactor({
        plugins: ['advanced']
    });   
});

I removed the redactor.js script from the automatically loaded scripts, in order to execute your plugin definition first.

Upvotes: 4

Related Questions