Ahmed Chergaoui
Ahmed Chergaoui

Reputation: 103

Listen to click events inside CKEditor dialog

I have a ckeditor instance, to which I added a custom dialog box using:

CKEDITOR.dialog.add('quicklinkDialog', function(editor) {
   return {
     title: 'Quick Links',
     minWidth: 400,
     minHeight: 200,

     contents: [
       {
        id: 'tab1',
        label: 'Add a quick link',
        elements: [
        {
         type: 'html',
         html: '<p>This is some text and then: <a href="">Click me!</a></p>'
        }]
   };
 });

I want to add a "click" event listener on the link inside my dialog box. When that link is clicked, content will be inserted into my textrea (the dialog box will also be closed).

Anyone knows how I might do this? Thanks in advance!

Upvotes: 2

Views: 2800

Answers (1)

oleq
oleq

Reputation: 15895

Here you go:

{
    type: 'html',
    html: '<p>This is some text and then: <a href="">Click me!</a></p>',
    onLoad: function( a ) {
        CKEDITOR.document.getById( this.domId ).on( 'click', function() {
            var dialog = this.getDialog();
            dialog.hide();
            dialog._.editor.insertHtml( this.html );
        }, this );
    }
}

See the API to know more.

Upvotes: 8

Related Questions