Fckeditor - removing tool bar items

I was working around for a couple of days to enable a feature were we can remove the tool bar items depending upon some permissions like hiding Style and Bold for a particular user group.
I don't find any feature in-built in the FCKeditor to do this , so thought of trying some hack on it.
The possible workaround I tried was this,

In the FCKeditor the editor/fckeditor.html page loads up all the configurations while start-up , so we can possibly remove the tool bar items for a specific Toolbarset before creating it.Here is how I did it.

In LoadToolbar() function in the fckeditor.html page I added the following lines,

function LoadToolbar()
{
var oToolbarSet = FCK.ToolbarSet = FCKToolbarSet_Create() ;
var removeToolBarSet=FCKURLParams['RemoveToolBarSet'] || '';
if ( oToolbarSet.IsLoaded )
StartEditor() ;
else
{
oToolbarSet.OnLoad = StartEditor ;

//get the current tool bar from the URL and look up in the FCKConfig.js

hyCurrentToolBar=FCKURLParams['Toolbar'] || 'Default' ;
var toolBarArray=FCKConfig.ToolbarSets[hyCurrentToolBar];

if(removeToolBarSet.indexOf('upload')!=-1){ //disable the upload Tab
FCKConfig.ImageUpload = false ;
}

//Remove the tool bar items specified in the list
var strippedToolBar=RemoveToolBarItems(toolBarArray,removeToolBarSet);
if(strippedToolBar){
FCKConfig.ToolbarSets[hyCurrentToolBar]=strippedToolBar;
}
oToolbarSet.Load( FCKURLParams['Toolbar'] || 'Default' ) ;
}
}


function RemoveToolBarItems(toolBarArray,removeToolBarSet){

if(removeToolBarSet && removeToolBarSet.length>0){

for(i=0;i<toolBarArray.length;i++){

var rowStrip=toolBarArray[i];

for(j=0;j<rowStrip.length;j++){

if(removeToolBarSet.indexOf(rowStrip[j])!=-1){

toolBarArray[i].splice(j,1);//dynamically removes the array item and re-arranges it

j--;
}
}
}


}
return toolBarArray;
}


In JAVA , in the FCKeditorTag.java add the following lines,

private String removeToolBarSet=null;
//add its getters and setters

in doStartTag() add,
if(removeToolBarSet!=null){
fcked.setRemoveRoolBarSet(removeToolBarSet);
}

then perform the same definitions in the FCKEditor.java and append the appropriate query string in the createIFrameHTML().

And all over just don't forget to give the attribute setting in tld specifications and also in the custom tag in JSP page!!! :)

It's as simple is it 8-) ..

Please feel free to comment me if any doubts and also If i am wrong..

Comments

Anonymous said…
Nice Post !!! Thank u..
Bunny said…
Hi there,
I'm using FCKedtor, and trying to customize the toolbar. can you please tell me that how to customize. I want to use the Basic toolbar but i want to add some more items to the basic one. Can you please tell me how to do that.
I used your code but its not working. Please advise me.
I really appreciate for your help.
M3hm0^2d: said…
Hi bunny,

You might want to take a look at the FCKeditor docs website FCKeditor Developer Docs. If any specific doubt you can always contact me. For a direction, you can use fckconfig.js and for adding new toolbar items of your own , you might want to look up how to write a plugin for the FCKeditor.
Anonymous said…
People should read this.

Popular posts from this blog

Hibernate queries are slow ! SQL Server's are not my type ? - Here is what you need to know!

IFTTT Service descriptions with Google Search

Detecting browser event closing in Javascript