How can i close CKEditor or tinyMCE on a click outside of the editor?

后端 未结 3 553
孤独总比滥情好
孤独总比滥情好 2021-01-14 12:55

I have text widgets that can be added on the page. A click should activate the div into a wysiwyg editor. A click anywhere outside of the editor should destroy the editor wi

3条回答
  •  迷失自我
    2021-01-14 13:11

    CKEditor seems to provide an API to "stopPropagation"

    So my solution would be to put an onclick event on the body, but stop propagation of the click event on the editor.

    e.g.

    var element = CKEDITOR.document.getById( 'myElement' );
    element.on( 'click', function( ev )
    {
        // The DOM event object is passed by the "data" property.
        var domEvent = ev.data;
        // Prevent the click to chave any effect in the element.
        domEvent.stopPropagation();
    });
    

    and the body event will be something like this (well, not exactly, but just to illustrate)

    $("body").click(function(event){
        element.destroy();
    });
    

    see here

提交回复
热议问题