Log in or register to post comments
Last post
lukaszzenko's picture
Joined: 03/08/2012
Posts: 1
CKEditor option startupMode causes js error
I was trying to find out what is wrong with this code for a few hours. After double-clicking on divs CKEditor correctly opens and after pressing down the button it correctly hides. But after clicking again on div it doesn't want to open again and then firebug returns an error "p is null" in line 86 in ckeditor.js.

Finally it turned out that the problem disappears when I turn off the option "startupMode: 'source'". Has anyone an idea what this behaviour is caused by? Is it a bug in CKEditor or I do something wrong. Version of CKEditor I use is 3.6.4. Thanks in advance for any help!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/admin/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
</head>

<body>
<h2>Vars</h2> 

<table>
    <tbody>
        <tr>
            <td>Cell no 1.1</td>
            <td><div class="editable" id="cell1">Cell no 1.2</div></td>
        </tr>
        <tr>
            <td>Cell no 2.1</td>
            <td><div class="editable" id="cell2">Cell no 2.2</div></td>
        </tr>
    </tbody>
</table>
<input type="submit" id="submit" value="Close"/>

<script type="text/javascript">

editor = false; 

function destroy_cke() {
    if (editor) {
        editor.updateElement();
        editor.destroy();
    }
}

function replace_div(div) {
    destroy_cke();
    editor = CKEDITOR.replace(div,{
        startupMode: 'source',
    });
}
$(document).ready (function() { 
    $('.editable').dblclick(function(e) {
        e.stopPropagation();
        var element = e.target || e.srcElement;
        while (element.nodeName.toLowerCase() != 'div' && (element.nodeName.toLowerCase() != 'div' || element.className.indexOf('editable') == -1 )) element = element.parentNode;
        replace_div(element);
    });

    $('#submit').click(function(){
        destroy_cke();
    });
});
</script>
</body>
</html>
alfonsoml's picture
Joined: 31/12/2006
Posts: 3704
Re: CKEditor option startupMode causes js error
You are not clearing your local "editor" variable.
Use this:

    function destroy_cke() {
        if (editor) {
            editor.updateElement();
            editor.destroy();
        }
      editor=null;
    }