Ed.onKeyDown in tinymce example

I have a new version of tinymce editor. I have a problem when I want to add ed.onKeyDown section. An error message appears in the firebug console:

TypeError: ed.onKeyDown - undefined

Prior to this, my full html file:

<textarea id="txtContent"></textarea> <p>Words left: <span id="txtContent-word-counter">200</span></p> <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script> <script type="text/javascript" src="tinymce\tinymce.jquery.js"></script> <script type="text/javascript"> tinymce.init({ selector: "textarea", setup: function(ed) { var text = ''; var span = document.getElementById(ed.id + '-word-counter'); if(span) { var wordlimit = span.innerHTML; ed.onKeyDown.add(function(ed, e) { text = ed.getContent().replace(/(< ([^>]+)<)/g, '').replace(/\s+/g, ' '); text = text.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); wordcount = wordlimit - (text.split(' ').length); span.innerHTML = wordcount; if(wordcount <= 0 && e.keyCode != 8) { return tinymce.dom.Event.cancel(e); } }); } } }); </script> 

Source: https://snipt.net/tamewhale/add-word-count-and-limit-to-tinymce/

+4
source share
2 answers

I had the same problem as switching from 3.x to 4.x Solution: http://www.tinymce.com/forum/viewtopic.php?pid=107019#p107019

+2
source

Maybe I'm wrong, but you are not trying to bind the already running event "ed.onKeyDown". I would suggest that you need to bind an object to this event. In addition, you must put init in the ready-made function of the document, as mentioned earlier by Chernovsky.

0
source

Source: https://habr.com/ru/post/1479249/


All Articles