Skip to content

Instantly share code, notes, and snippets.

@abidibo
Created November 9, 2011 14:42
Show Gist options
  • Save abidibo/1351623 to your computer and use it in GitHub Desktop.
Save abidibo/1351623 to your computer and use it in GitHub Desktop.
A proof of character counter for fck editor 2.x
// requires mootools-core bind function
function FCKeditor_OnComplete(editorInstance){
editorInstance.EditorDocument.addEventListener('keypress', checkCharacters.bind(editorInstance));
}
function checkCharacters(e) {
var characters = 0;
var clean_tag = this.GetHTML().replace(/<\/?.*?>|&nbsp;/gi, '');
var clean_string = clean_tag.replace(/&quot;/gi, ' '); // add more entities
var add = e.charCode ? 1 : (e.keyCode==46 || e.keyCode==8) ? -1 : 0;
characters = clean_string.length + add
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment