Hi, I started to write a Chars counter plugin. It seems to work well enough, but there's still much work to do... and I'm not a so good coder!!!
So, this is what I wrote:
// File: /FCKEditor/plugins/charscounter/fckplugin.js
//
/*
* Chars Counter Plugin
*
* File Name: fckplugin.js -
*
*
* File Author: Luigi Maniscalco l.maniscalco@visioni.info
*/
function CharsCounter()
{
var text=FCK.GetXHTML();
text=text.replace(/<[^>]+>/g,''); // Don't count HTML tags
text=text.replace(/&[^;]+;/g,' '); // Count &chr; as one keystroke
window.parent.document.getElementById(FCK.Name+'_cnt').value = FCKConfig.MaxLength-text.length; // Update left chars
}
if (FCKBrowserInfo.IsGecko) // Mozilla
{
FCK.Events.AttachEvent("OnPaste",CharsCounter); // OnPaste event - This seems not to work if there is the next line
FCK.EditorDocument.addEventListener('keydown',CharsCounter,true); // OnKeyDown event - This works, but seems to make the previous line not to work
}
if (FCKBrowserInfo.IsIE) // IE
{
FCK.EditorDocument.attachEvent("onpaste",CharsCounter); // OnPaste event - This should be right, but doesn't work
FCK.EditorDocument.attachEvent("onkeydown",CharsCounter); // OnKeyDown event - This works
}
//FCKTools.AttachToLinkedFieldFormSubmit(Validate);
//
// EOF
...and in your HTML:
<!-- Begin -->
<textarea id="mytextarea">somestuff</textarea>
<input type="text" id="mytextarea_cnt" value="255">
<script type="text/javascript">
var oFCKeditor = new FCKeditor('mytextarea');
oFCKeditor.BasePath = '../FCKeditor/';
oFCKeditor.Config['CustomConfigurationsPath'] = '/<abspath>/FCKeditor/myconfig.js';
oFCKeditor.Config['MaxLength'] = 255;
oFCKeditor.ReplaceTextarea();
</script>
<!-- End -->
This suppose that you have an external input text field which is identified by textarea.id+"_cnt";
To do list:
1) The function FCK.GetXHTML() seems to catch the code BEFORE the new char is typed... so the counter is always 1 step in late;
2) paste is not caught correctly in Gecko, in IE this code doesn't work;
3) I'm trying to write a "validation" function that prevent submitting if the counter value is -1 or less (I thought something like: FCKTools.AttachToLinkedFieldFormSubmit(Validate);... what do you think?)
I'm still working on this code, but as I said I'm a little much more of a beginner, so any help would be appreciated.
Thank you in advance!
gi_gio.
So, this is what I wrote:
// File: /FCKEditor/plugins/charscounter/fckplugin.js
//
/*
* Chars Counter Plugin
*
* File Name: fckplugin.js -
*
*
* File Author: Luigi Maniscalco l.maniscalco@visioni.info
*/
function CharsCounter()
{
var text=FCK.GetXHTML();
text=text.replace(/<[^>]+>/g,''); // Don't count HTML tags
text=text.replace(/&[^;]+;/g,' '); // Count &chr; as one keystroke
window.parent.document.getElementById(FCK.Name+'_cnt').value = FCKConfig.MaxLength-text.length; // Update left chars
}
if (FCKBrowserInfo.IsGecko) // Mozilla
{
FCK.Events.AttachEvent("OnPaste",CharsCounter); // OnPaste event - This seems not to work if there is the next line
FCK.EditorDocument.addEventListener('keydown',CharsCounter,true); // OnKeyDown event - This works, but seems to make the previous line not to work
}
if (FCKBrowserInfo.IsIE) // IE
{
FCK.EditorDocument.attachEvent("onpaste",CharsCounter); // OnPaste event - This should be right, but doesn't work
FCK.EditorDocument.attachEvent("onkeydown",CharsCounter); // OnKeyDown event - This works
}
//FCKTools.AttachToLinkedFieldFormSubmit(Validate);
//
// EOF
...and in your HTML:
<!-- Begin -->
<textarea id="mytextarea">somestuff</textarea>
<input type="text" id="mytextarea_cnt" value="255">
<script type="text/javascript">
var oFCKeditor = new FCKeditor('mytextarea');
oFCKeditor.BasePath = '../FCKeditor/';
oFCKeditor.Config['CustomConfigurationsPath'] = '/<abspath>/FCKeditor/myconfig.js';
oFCKeditor.Config['MaxLength'] = 255;
oFCKeditor.ReplaceTextarea();
</script>
<!-- End -->
This suppose that you have an external input text field which is identified by textarea.id+"_cnt";
To do list:
1) The function FCK.GetXHTML() seems to catch the code BEFORE the new char is typed... so the counter is always 1 step in late;
2) paste is not caught correctly in Gecko, in IE this code doesn't work;
3) I'm trying to write a "validation" function that prevent submitting if the counter value is -1 or less (I thought something like: FCKTools.AttachToLinkedFieldFormSubmit(Validate);... what do you think?)
I'm still working on this code, but as I said I'm a little much more of a beginner, so any help would be appreciated.
Thank you in advance!
gi_gio.
Re: Chars counter plugin
toolbar button isn't working. It displays:
<label id="CharsCounterLabel">0 / 0 / 10</label>
Does anyone have a suggestion?
Re: Chars counter plugin
I've exactly the same problem.
At the top of FCK editor, where the counter should appear, I get this :
<label id="CharsCounterLabel">0 / 0 / 10</label>
Is this plugin ok with 2.6.4?