In the HTML sample 08 included with the FCKeditor (editor/_samples/html/sample08.html), there are buttons that show how to use the FCKeditor javascript API. Amoung those buttons there is one reading "Interact with the Editor Area DOM" conlcik of this button the function GetLength is fired that returns the text length of editor's content. You can see how it works and try to pour it into a plugin that 'undoes' the last typing action or -even better- that cancels this action from having affect (placing the typed character)
function GetLength() { // This functions shows that you can interact directly with the editor area // DOM. In this way you have the freedom to do anything you want with it.
// Get the editor instance that we want to interact with. var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
// Get the Editor Area DOM (Document object). var oDOM = oEditor.EditorDocument ;
var iLength ;
// The are two diffent ways to get the text (without HTML markups). // It is browser specific.
if ( document.all ) // If Internet Explorer. { iLength = oDOM.body.innerText.length ; } else // If Gecko. { var r = oDOM.createRange() ; r.selectNodeContents( oDOM.body ) ; iLength = r.toString().length ; }
alert( 'Actual text length (without HTML markups): ' + iLength + ' characters' ) ; }
RE: Character counter with FCKeditor
RE: Character counter with FCKeditor
mystring = oEditor1.GetXHTML(null).replace(/<[^>]*>/g, '');
Then you'll need another few to remove the nbsps and so forth.
RE: Character counter with FCKeditor
You can see how it works and try to pour it into a plugin that 'undoes' the last typing action or -even better- that cancels this action from having affect (placing the typed character)
function GetLength()
{
// This functions shows that you can interact directly with the editor area
// DOM. In this way you have the freedom to do anything you want with it.
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
// Get the Editor Area DOM (Document object).
var oDOM = oEditor.EditorDocument ;
var iLength ;
// The are two diffent ways to get the text (without HTML markups).
// It is browser specific.
if ( document.all ) // If Internet Explorer.
{
iLength = oDOM.body.innerText.length ;
}
else // If Gecko.
{
var r = oDOM.createRange() ;
r.selectNodeContents( oDOM.body ) ;
iLength = r.toString().length ;
}
alert( 'Actual text length (without HTML markups): ' + iLength + ' characters' ) ;
}