Florent
Florent

Reputation: 761

Insert iframe in div from onOk of CKEDITOR.dialog

I use CKEditor and I have got problem for insert iframe in div element in my editor when the user click on the OK button in my Dialog. This does not work. When the user clicks on the button does nothing happen (I have no error message). So he should shut my popup and insert a div containing my iframe inside my editor

Can you help me ?

this is my code :

CKEDITOR.dialog.add( 'postVideoDialog', function( editor ) {

return {
    title : 'Add Video',
    minWidth : 400,
    minHeight : 80,
    contents :
    [
        {
            id : 'video',
            label : 'Add Video',
            elements :
                [
                    {
                        type : 'text',
                        id : 'url',
                        label : 'Enter a URL from Vimeo :',
                        validate : function()
                                    {
                                        var url = this.getValue();
                                        var regex1=/^(http:\/\/)vimeo.com\/[0-9]{3,}$/g;
                                        var regex2=/^(http:\/\/)player.vimeo.com\/video\/[0-9]{3,}$/g;

                                        if(regex1.test(url) || regex2.test(url)){
                                            return true
                                        }else{
                                            alert("Url incorrect");
                                            return false;
                                        }
                                    },
                        required : true,
                        commit : function( data )
                        {
                            data.url = this.getValue();
                        }
                    },
                ]
        }
    ],
    onOk : function()
    {
        var dialog = this,
        data = {},
        iframe = editor.document.createElement( 'iframe' ),
        div = editor.document.createElement('div');
        this.commitContent( data );

        var regex=/^(http:\/\/)vimeo.com\/[0-9]{3,}$/g; //http://vimeo.com/25329849

        if(regex.test(data.url)){
            var idVideo = data.url.match(/[0-9]{3,}$/g);
            data.url = "http://player.vimeo.com/video/" + idVideo;
        }

        div.setAttribute('class', 'video');

        iframe.setAttribute( 'src', data.url + "?byline=0&portrait=0&color=ffffff");
        iframe.setAttribute( 'width', '620' );
        iframe.setAttribute( 'width', '349' );
        iframe.setAttribute( 'frameborder', '0');


        div.insertElement(iframe); //problem is here !
        editor.insertElement(div);
    }
}; });

Upvotes: 0

Views: 1573

Answers (1)

Spons
Spons

Reputation: 1591

Found it..

Read the documentation please: docs.ckeditor.com/#!/api/CKEDITOR.dom.element

Elements don't have a insertElement method. This is a method of the editor try this:

    iframe.appendTo(div); //problem is solved here!
    editor.insertElement(div);

Instead of your previous code:

    div.insertElement(iframe); //problem is here !
    editor.insertElement(div);

Upvotes: 1

Related Questions