Gabriel
Gabriel

Reputation: 970

CKEditor One instance for multiple ID's

Can i use one configuration for CKeditor for multiple ID's?

i have this config in my page :

var editor = CKEDITOR.replace('dsi3',{  
            toolbar :
                [
                    { name: 'basicstyles', items : [ 'Bold','Italic'] },
                    { name: 'paragraph', items : [ 'BulletedList'] }

                ],
            width: "210px",
            height: "140px"
        });

but i have to past again and again for different ids, instead i wanna do something like this :

var editor = CKEDITOR.replace('dsi3, dsi4, dsi5, dsi6',{    
            toolbar :
                [
                    { name: 'basicstyles', items : [ 'Bold','Italic'] },
                    { name: 'paragraph', items : [ 'BulletedList'] }

                ],
            width: "210px",
            height: "140px"
        });

Upvotes: 1

Views: 2017

Answers (1)

Nabil Kadimi
Nabil Kadimi

Reputation: 10394

You can user a variable for the options.

var editor_config = {
    toolbar: [
        {name: 'basicstyles', items: ['Bold', 'Italic']},
        {name: 'paragraph', items: ['BulletedList']}
    ],
    width: "210px",
    height: "140px"
};

CKEDITOR.replace('dsi3', editor_config );
CKEDITOR.replace('dsi4', editor_config );
CKEDITOR.replace('dsi5', editor_config );
CKEDITOR.replace('dsi6', editor_config );

Or with jQuery, matching all ids starting with "dsi":

$('[id^=dsi]').ckeditor({
    toolbar: [
        {name: 'basicstyles', items: ['Bold', 'Italic'] },
        {name: 'paragraph', items: ['BulletedList'] }
    ],
    width: "210px",
    height: "140px"
});

Upvotes: 5

Related Questions