How can I implement TinyMCE with Require.js?

后端 未结 3 1640
青春惊慌失措
青春惊慌失措 2020-12-30 08:59

I am currently passing in the TinyMCE source as a dependency, and then calling tinyMCE.init({}); but it is not initializing TinyMCE. When I console.log TinyMCE, it retur

3条回答
  •  礼貌的吻别
    2020-12-30 09:00

    You can use 'shim' for requirejs 2.1.0 or higher, see example of main script below:

    requirejs.config({
        baseUrl: "js",
        paths: {
            tinyMCE: 'libs/tinymce/tiny_mce'
        },
        shim: {
            tinyMCE: {
                exports: 'tinyMCE',
                init: function () {
                    this.tinyMCE.DOM.events.domLoaded = true;
                    return this.tinyMCE;
                }
            }
        }
    });
    
    requirejs([
        'tinyMCE'
    ], function (tinyMCE) {
        console.log(tinyMCE);
    
        // your code here
    });
    

    Edit: I added iimuhin’s snippet from below in the comments. It doesn’t seem to work without it; I added it because future searchers will appreciate avoiding the added IE headache.

提交回复
热议问题