CKEDITOR.plugins.add('tirusgallery', { icons: 'gallery', init: function(editor) { editor.addCommand('tirusgalleryDialog', new CKEDITOR.dialogCommand('tirusgalleryDialog')); editor.ui.addButton('Tirusgallery', { label: 'Insert gallery', command: 'tirusgalleryDialog', toolbar: 'insert' }); } }); CKEDITOR.dialog.add('tirusgalleryDialog', function(editor) { var galleries = $.getJSON("/gallery/getgalleries", function(data) { var dataArray = []; dataArray.push([editor.lang.common.notSet, '']); $.each(data.result, function(index, value) { dataArray.push([value, "" + index]); }); console.log(dataArray); return dataArray; }); var config = { title: 'Galleries', minWidth: 400, minHeight: 100, contents: [ { id: 'tab-basic', label: 'Choose your gallery', elements: [ { type: 'select', id: 'category', label: 'Category', items: $.getJSON("/gallery/getgalleries", function(data) { var dataArray = []; dataArray.push([editor.lang.common.notSet, '']); $.each(data.result, function(index, value) { dataArray.push([value, "" + index]); }); console.log(dataArray); return dataArray; }) }, { type: 'text', id: 'album', label: 'Album', validate: CKEDITOR.dialog.validate.notEmpty("Select album, which you want to add") } ] } ], onOk: function() { $.getJSON("/gallery/getgalleryalbum/4", function(data) { console.log(data.result); }); var dialog = this; var abbr = editor.document.createElement('gallery'); //abbr.setAttribute('title', dialog.getValueOf('tab-basic', 'title')); abbr.setText('[*]albumList,' + dialog.getValueOf('tab-basic', 'album') + '[/*]'); editor.insertElement(abbr); } }; return config; });