How to set up CKEditor for multiple instances with different heights?

前端 未结 6 472
甜味超标
甜味超标 2021-01-02 01:01

I\'d like to have multiple instances of CKEditor based on the same config settings, but with different heights. I tried setting up config with the default height, s

6条回答
  •  暖寄归人
    2021-01-02 01:22

    Solution above from Reinmar is working for me, however I decided to give 1 more solution that i used before this one.

    It's really simple, all you need to know is that ckeditor create content div element for every instance with almost the same id, only difference is incremental value. So if you have 2,3,4.. instances only difference will be ordinal number. Code is here:

        CKEDITOR.on('instanceReady', function(){
        $('#cke_1_contents').css('height','200px');
    }); 
    

    This event will be activated for every instance you have, so if you want to set height for all instances you could create global variable and use it like x in #cke_"+x+"contents, every time event is activated increase x for 1, check which instance in row is with simple if and then set height.

        var x=1;
    CKEDITOR.on('instanceReady', function(){
        if(x==1) h='200px';
        else if(x==2)h='400px';
        else if(x==3)h='700px';
        $('#cke_'+x+'_contents').css('height',h);
        x++;
    }); 
    

    This is not best solution but it is working, problem is you actually see content div resizing.

提交回复
热议问题