新创建的CKEditor实例上的鼠标事件问题

时间:2013-02-08 22:37:24

标签: ckeditor

我正在尝试创建一个新的CKEditor ver4实例来响应用户点击一个元素。由于应用程序的性质,我无法使用CKEditor Sample中概述的“autoInline”功能。虽然下面的示例确实创建了一个编辑器实例,但该实例存在严重问题。当用户点击它们时,内联实例应该会消失。但是,在此示例中,用户必须先单击,单击返回实例,然后再次单击“离开”。我该如何防止这种情况?

<!doctype html>
<html>
<head>
    <script src="jspath/ckeditor.js"></script>
    <script>
        var editor = null;
        CKEDITOR.disableAutoInline = true;
        function init() {
        var e2 = document.getElementById("element2");
        e2.addEventListener("click", function () {
        if(!editor) {
                editor = CKEDITOR.inline(e2);
                editor.on('instanceReady', function () {
                    console.log("instanceReady")
                    console.log(editor.focusManager.hasFocus);
                });
                editor.on('focus', function() {
                    console.log("focus");
                })
                editor.on('blur', function() {
                    console.log("blur");
                    editor.destroy();
                    editor = null;
                })
            }
        })
    }
</script>
</head>
<body onload="init()">
    <div tabindex="0" id="element2" style="background-color: yellow;" contentEditable = true>Element 2</div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

尽管editor.focusManager.hasFocus是真的,但编辑的元素实际上并没有集中注意力。也许这是一个错误?无论如何,将editor.focus();添加到instanceReady函数可以解决问题。