I figured it out how to customize the Context Menus! In fact you don't need to change any internal code, just need to overwrite two internal functions at your custom fckplugin.js! Here is the code I put at the bottom of the fckplugin.js file:
/** * Add an additional Context Menu for the "Variable" plugin * Overwrite the internal function that returns the Context Menu items */ FCKContextMenu.__GetGroup = FCKContextMenu._GetGroup; FCKContextMenu._GetGroup = function( groupName ) { var oGroup ;
switch ( groupName ) { case 'Variable' : oGroup = new FCKContextMenuGroup() ; oGroup.Add( new FCKContextMenuItem( this, 'Variable', FCKLang.VariableProp, true ) );
/** * Overwrite the internal function that tells the visibility of items * in a Context Menu */ oGroup.__RefreshState = oGroup.RefreshState; oGroup.RefreshState = function() { // Get the actual selected tag (if any). var oTag = FCKSelection.GetSelectedElement() ; var sTagName ;
if ( oTag ) sTagName = oTag.tagName ; // Set items visibility. this.SetVisible( sTagName == 'INPUT' && ( oTag.type == 'text' ) ) ; /** * Calls the original function */ this.__RefreshState(); } break ; default: /** * Calls the original function */ oGroup = this.__GetGroup(groupName); } return oGroup; }
It seems to me that this is not an easy thing to do since your post ages 9 months now! Can somebody with karma please help and tell us if there is a way to add items to Context Menu for plugins ?
RE: Add menu Item to Context menu
/**
* Add an additional Context Menu for the "Variable" plugin
* Overwrite the internal function that returns the Context Menu items
*/
FCKContextMenu.__GetGroup = FCKContextMenu._GetGroup;
FCKContextMenu._GetGroup = function( groupName )
{
var oGroup ;
switch ( groupName )
{
case 'Variable' :
oGroup = new FCKContextMenuGroup() ;
oGroup.Add( new FCKContextMenuItem( this, 'Variable', FCKLang.VariableProp, true ) );
/**
* Overwrite the internal function that tells the visibility of items
* in a Context Menu
*/
oGroup.__RefreshState = oGroup.RefreshState;
oGroup.RefreshState = function()
{
// Get the actual selected tag (if any).
var oTag = FCKSelection.GetSelectedElement() ;
var sTagName ;
if ( oTag )
sTagName = oTag.tagName ;
// Set items visibility.
this.SetVisible( sTagName == 'INPUT' && ( oTag.type == 'text' ) ) ;
/**
* Calls the original function
*/
this.__RefreshState();
}
break ;
default:
/**
* Calls the original function
*/
oGroup = this.__GetGroup(groupName);
}
return oGroup;
}
RE: Add menu Item to Context menu
RE: Add menu Item to Context menu