Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load ckeditor via requirejs

I'm having issues trying to load ckeditor via requirejs (I've tried converting the main ckeditor js file into individual modules but that has just caused all hell to break loose) and so I'm now checking to see if there is a very simple way to do this that I've missed.

I know requirejs allows you to load normal js scripts so maybe just loading the ckeditor.js file (un-edited, so it's still an IIFE/self-executing function) - would that work with requirejs or if you're using requirejs for loading modules, does the entire project then need to be module based?

Any help appreciated.

Kind regards, Mark

like image 797
Integralist Avatar asked Jan 03 '12 13:01

Integralist


2 Answers

Alternatively, you can create a RequireJS shim to load things in the correct order, and alias proper RequireJS module names to the CKEditor distribution files.

This means your module still declares it is dependant on CKEditor, which is a lot nicer than having it just show up by magic.

require.config({
shim: {
    'ckeditor-jquery':{
        deps:['jquery','ckeditor-core']
    }
},
 paths: {
    "jquery": '/javascript/jquery-1.7.1/jquery.min',
    'ckeditor-core':'/javascript/ckeditor-3.6.4/ckeditor',
    'ckeditor-jquery':'/javascript/ckeditor-3.6.4/adapters/jquery'
}
});

then in a module you can depend on ckeditor-jquery (or ckeditor-core for that matter, if you don't need the jQuery integration) and know it'll be available:

require(
[
    "jquery",
    "ckeditor-jquery"
],
function( _jquery_ ) {

    $('#editorContent2').ckeditor({
        customConfig : '',
        skin:'office2003'
    });
}
}
like image 100
Tom Chiverton Avatar answered Oct 12 '22 11:10

Tom Chiverton


Another way to do that:

var require = {
    "shim": {
        "path/foo/ckeditor/ckeditor": { "exports": "CKEDITOR" }
    }
};

define(['moduleX', 'path/foo/ckeditor/ckeditor'], function (x, ckeditor) { 

     ckeditor.editor.prototype.fooFunc = function() {

     };
});
like image 29
Gencebay Avatar answered Oct 12 '22 12:10

Gencebay