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
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!
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)
RE: the word count function (wordcount)
Thanks