Hello.
I hope that some of you have worked with this editor.
I would like to write a plugin to add a link to the user profile. That is, he entered the nickname, ran ajax through the database, found the users who were suitable, displayed the list, poked the right one, a link was added to the editor.
My problem is this: how to add a button to the dialog box and hang an event handler on it?
UPD: it decided, now somehow you need to request the Ajax results and shove them into select
|
1 answer
Following the simple guide you can come to this code:
structure:
-plugins |-example -|-dialogs --|-example.js -|-plugin.js
The plugin.js
file contains:
CKEDITOR.plugins.add( 'example', { init: function( editor ) { editor.ui.addButton( 'Example', { label: 'Insert user', command: 'exampleDialog', }); CKEDITOR.dialog.add( 'exampleDialog', this.path + 'dialogs/example.js' ); editor.addCommand( 'exampleDialog', new CKEDITOR.dialogCommand( 'exampleDialog' ) ); } });
The file example.js
contains:
CKEDITOR.dialog.add("exampleDialog",function(editor){ var select; var user=''; return { title:'Добавить пользователя', minWidth:390, minHeight:230, contents:[{ elements:[{ type: 'text', id: 'ajax', label: 'Поиск пользователя', onChange: function( api ) { // Load data asynchronously. CKEDITOR.ajax.load('/?user=' + this.getValue(), function( data ) { var users = JSON.parse(data); for(var foo in users) { select.add(users[foo]); } }); } },{ type: 'select', id: 'ajax_select', label: 'Найденные пользватели', items: [''], onChange: function( api ) { user = this.getValue(); }, onLoad: function() { select = this; } }] }], onOk: function() { var link = editor.document.createElement( 'a' ); link.setAttribute('url', '/users/' + user); link.setText('комментарий к: ' + user); editor.insertElement( link ); } } });
Dare! ckeditor
n't forget to build ckeditor
so that there is an ajax
module.
- Thank you, kind man, helped out! By the way, it seems to be not the first time. - sinedsem
|