How to use TinyMCE functions on text without actually selecting that text?

后端 未结 2 893
旧巷少年郎
旧巷少年郎 2021-01-13 06:35

I have various

s on my page, which, when clicked, convert into TinyMCE editor sections. So the user can just double click on the div and then edit t
2条回答
  •  醉酒成梦
    2021-01-13 07:27

    The answer for me was to use a combination of @Thariama's setup code:

    tinyMCE.init({ ....
        setup : function(ed) {  
        ed.onInit.add(function(ed, evt) {
    
            ed.getBody().setAttribute('contenteditable', false);
    
            var range = ed.selection.dom.createRng();
    
            range.setStartBefore(ed.getBody().firstChild);
            range.setEndAfter(ed.getBody().lastChild);
            ed.selection.setRng(range);
        });
    }
    });
    

    With a way to disable keypresses in the textarea, i.e. if my textarea has an ID of TAID, then I added this code:

    $('#TAID_ifr').contents().find('html').bind('keypress', function(e){return false;});

提交回复
热议问题