hi,
i tried for 2 days now to find the way to add a button to the toolbar that simply calls a javascript function of my choice. i tried modifying the placeholder plugin, the findreplace plugin, adding a command to the core - and totally failed. i read all i could find on this forum on the subject and nothing seemed to help... i must have missed something really simple and nice because there has got to be a way, no?
what i want is this: a button on the toolbar that will preform a word count and will display the result in a javascript alert. no dialog or fancy stuff. can you help?
million thanks!
i tried for 2 days now to find the way to add a button to the toolbar that simply calls a javascript function of my choice. i tried modifying the placeholder plugin, the findreplace plugin, adding a command to the core - and totally failed. i read all i could find on this forum on the subject and nothing seemed to help... i must have missed something really simple and nice because there has got to be a way, no?
what i want is this: a button on the toolbar that will preform a word count and will display the result in a javascript alert. no dialog or fancy stuff. can you help?
million thanks!
RE: add a non-dialog button: close to despare
mmm... no changed in FCKeditor/fckconfig.js ?



i tried it just like you wrote and got nothing on the toolbar, then i tried adding 'abutton' as an item to the toolbar in FCKeditor/fckconfig.js and got the "unknown toolbar item 'abutton'" alert...
sorry if i'm missing some obvious thing here - i'm very new at this...
thanks so much for helping! i will write here the wordcount function once i manage to get it to work
RE: add a non-dialog button: close to despare
This one counts the chars in the body. Feel free to modify and share* w/others.
*what YOU come up with =-)
Begin editor/plugins/abutton/fckplugin.js
//#######################################
// ### Dave
var FCKDaveCommand = function()
{
this.Name = 'Dave' ;
}
FCKDaveCommand.prototype.Execute = function()
{
// Get the text in the body.
var oBody = FCK.EditorDocument.body.innerHTML ;
alert(oBody.length);
}
FCKDaveCommand.prototype.GetState = function()
{
return FCK_TRISTATE_OFF ;
}
// Create the toolbar button.
function regCButton(daButton) {
FCKCommands.RegisterCommand( daButton , new FCKDaveCommand() ) ;
var oReplaceItem = new FCKToolbarButton( daButton, FCKLang['Dlg' + daButton + 'Title'] ) ;
oReplaceItem.IconPath = FCKConfig.PluginsPath + 'abutton/button.'+ daButton + '.gif' ;
FCKToolbarItems.RegisterItem( daButton, oReplaceItem ) ;
}
regCButton('abutton');
//#######################
END editor/plugins/abutton/fckplugin.js
HTH, happy trails, etc., etc.. (-:
RE: add a non-dialog button: close to despare
FCKConfig.Plugins.Add( 'abutton', 'en,it' ) ;
And maybe it will work then. =-)
-ps it doesn't really have en or it, but it would be nice to stick to the standard and use language files. (-=
RE: add a non-dialog button: Bless You!
bless you, xenden! it works in IE

thanks so much! now... can we get it to work on firefox? i'll try. if you have any tips - do tell.
i'll upload the whole thing soon.
thanks again
the word count function (wordcount)
this script now works for both IE and FF (tested on win2000). the following code replaces the "FCKDaveCommand.prototype.Execute = function() {...}" code given above in the fckplugin.js:
////////////////////////////// begin
FCKDaveCommand.prototype.Execute = function()
{
// Get the length of the text including html tags
var oBody = FCK.EditorDocument.body.innerHTML ;
var chars = (oBody.length);
// Excluding html tags
var start_tag = /<.*?>/g;
var end_tag = /<\/.*?>/g;
var nohtml = oBody.replace(end_tag,'');
nohtml = nohtml.replace(start_tag,'');
var temp_arr = nohtml.split(/[^\b\w+\b]/g);
var arr = new Array(); arr_index = 0;
for(i = 0; i < temp_arr.length; i++){
if(temp_arr[i] != ""){
arr[arr_index] = temp_arr[i];
arr_index++;
}
}
alert(arr.length + " Words [not including html tags]\n\n" + chars + " Characters [including html tags]");
}
////////////////////////////// end
RE: the word count function (wordcount)
Beautiful. I know it will be useful to other people as well.

Nice Work!
RE: the word count function (wordcount)
Thanks