How to load ckeditor via requirejs

守給你的承諾、 提交于 2019-12-18 13:01:33

问题


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


回答1:


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'
    });
}
}



回答2:


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() {

     };
});



回答3:


OK, it seems I answered my own question here.

Instead of trying to break ckeditor down into modules I just used RequireJs to load the script in it's entirety.

require(['require', 'dependancy-A', 'dependancy-B', 'dependancy-C'], function(require, A, B, C){

    // this = [object DOMWindow]
    // CKEDITOR_BASEPATH is a global variable
    this.CKEDITOR_BASEPATH = '/ckeditor/';

    require(['/ckeditor/ckeditor'], function(){
        // Code to create a new editor instance
    });

});

```



来源:https://stackoverflow.com/questions/8713194/how-to-load-ckeditor-via-requirejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!