Search code examples
javascriptckeditor

CKEditor link dialog removing protocol


In my CKEditor I removed the 'linkType' and 'protocol' inputs of the link dialog.

   CKEDITOR.on( 'dialogDefinition', function( ev )
    {
        var dialogName = ev.data.name;
        var dialogDefinition = ev.data.definition;

        if ( dialogName == 'link' )
        {
            var infoTab = dialogDefinition.getContents( 'info' );
            infoTab.remove( 'linkType' );
            infoTab.remove( 'protocol' );
        }

    });

However, evertype I type in something like https://google.com as soon as I type in the 'g' the https:// gets removed.
I checked the output and it always says http:// disregarding the input.

How can I turn this stupid behaviour off?


Solution

  • After much research, debugging and tweaking, I've finally managed to pull this off!!!

    Here's how I do it:

    CKEDITOR.on('dialogDefinition', function(e) {
        // NOTE: this is an instance of CKEDITOR.dialog.definitionObject
        var dd = e.data.definition; 
    
        if (e.data.name === 'link') {
            dd.minHeight = 30;
    
            // remove the unwanted tabs
            dd.removeContents('advanced');
            dd.removeContents('target');
            dd.removeContents('upload');
    
            // remove all elements from the 'info' tab
            var tabInfo = dd.getContents('info');
            while (tabInfo.elements.length > 0) {
                tabInfo.remove(tabInfo.elements[0].id);
            }
    
            // add a simple URL text field
            tabInfo.add({
                type : 'text',
                id : 'urlNew',
                label : 'URL',
                setup : function(data) {
                    var value = '';
                    if (data.url) {
                        if (data.url.protocol) {
                            value += data.url.protocol;
                        }
                        if (data.url.url) {
                            value += data.url.url;
                        }
                    } else if (data.email && data.email.address) {
                        value = 'mailto:' + data.email.address;
                    }
                    this.setValue(value);
                },
                commit : function(data) {
                    data.url = { protocol: '', url: this.getValue() };
                }
            });
        }
    });