Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 651
Zulakis Avatar asked Oct 01 '12 15:10

Zulakis


4 Answers

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() };
            }
        });
    }
});
like image 121
lance-java Avatar answered Oct 14 '22 02:10

lance-java


I'm afraid there's no way to change it. You have to manually edit a few lines of the code to make it working your way.

like image 20
oleq Avatar answered Oct 14 '22 03:10

oleq


Here's how I removed the protocol in v4.5.1:

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('protocol');

        var url = infoTab.get('url');
        url.onKeyUp = function(){};
        url.setup = function(data) {
            this.allowOnChange = false;
            if (data.url) {
                var value = '';
                if (data.url.protocol) {
                    value += data.url.protocol;
                }
                if (data.url.url) {
                    value += data.url.url;
                }
                this.setValue(value);
            }
            this.allowOnChange = true;
        };
        url.commit = function(data) {
            data.url = { protocol: '', url: this.getValue() };
        };
    }
});
like image 43
Jonathan Avatar answered Oct 14 '22 04:10

Jonathan


I recently found a way to hide the Link Type so you don't have to remove it totally. Set the style to display: none like the following:

infoTab.get( 'linkType' ).style = 'display: none';

I think it works for the Protocol as well, but I haven't tested it. I answered the same question here

Hope this helps someone!

like image 1
medBouzid Avatar answered Oct 14 '22 03:10

medBouzid