<span id="total-characters"></span>
let charLimit = 2000;
callbacks: { onKeydown: function(e) { let characters = $('#textarea').summernote('code').replace(/(<([^>]+)>)/ig, ""); let totalCharacters = characters.length; $("#total-characters").text(totalCharacters + " / " + charLimit); var t = e.currentTarget.innerText; if (t.trim().length >= charLimit) { if (e.keyCode != 8 && !(e.keyCode >= 37 && e.keyCode <= 40) && e.keyCode != 46 && !(e.keyCode == 88 && e.ctrlKey) && !(e.keyCode == 67 && e.ctrlKey)) e.preventDefault(); } }, onKeyup: function(e) { var t = e.currentTarget.innerText; $('#textarea').text(charLimit - t.trim().length); }, onPaste: function(e) { let characters = $('#textarea').summernote('code').replace(/(<([^>]+)>)/ig, ""); let totalCharacters = characters.length; $("#total-characters").text(totalCharacters + " / " + charLimit); var t = e.currentTarget.innerText; var bufferText = ((e.originalEvent || e).clipboardData || window.clipboardData).getData('Text'); e.preventDefault(); var maxPaste = bufferText.length; if (t.length + bufferText.length > charLimit) { maxPaste = charLimit - t.length; } if (maxPaste > 0) { document.execCommand('insertText', false, bufferText.substring(0, maxPaste)); } $('#textarea').text(charLimit - t.length); } }
Sign up for our newsletter to stay up to date.
We care about the protection of your data. Read our Privacy Policy.
Schopenhauerstr. 71
80807 München
max@42coders.com
+49 (0)176 / 724 306 82
© 2024 42coders All rights reserved.