This is a migrated thread and some comments may be shown as answers.

Disabling ContextMenu via javascript

3 Answers 75 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Michael Pullella
Top achievements
Rank 1
Michael Pullella asked on 05 Apr 2010, 05:04 PM
Hi

I have an editor with custom toolbar buttons which I am able to enable / disable via javascript using the following code:
                function OnClientSelectionChange(editor, args) {  
                    var enableButton = (editor.getSelection().getText().length > 0) ? 0 : -1;  
                    editor.getToolByName("tbiEntity").setState(enableButton);  
                        //more buttons are being disbled (not showing for brevity)...  
                } 

The custom buttons that I am showing in my toolbar are also a custom contextMenu as in:
        <contextMenu forElement="*">  
            <tool name="tbiEntity" Text="Entity (Ctrl+Shift+E)" /> 
<!-- more here --> 
        </contextMenu>       

The toolbar buttons now only show when the user has selected some text (works great), however, I need to disable / enable the context menus when I am enabllng / disabling my toolbar buttons. 

How do I get a ref to the conextmenu via javascript, and do the contextmenus have a setState property?

3 Answers, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 06 Apr 2010, 10:27 AM
Hi Michael,

In order to get reference to the context menus via Javascript you can use the client method getContextMenuByTagName(), e.g.:
<telerik:RadEditor ID="RadEditor1" runat="server" OnClientLoad="OnClientLoad">
</telerik:RadEditor>
 
<script type="text/javascript">
    function OnClientLoad(editor, args)
    {
        var imgMenu = editor.getContextMenuByTagName("IMG");
 
        ....
    }
</script>

I believe the following CodeLibrary and Forum Thread will be helpful.

All the best,
Dobromir
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Michael Pullella
Top achievements
Rank 1
answered on 07 Apr 2010, 01:10 PM
Thank you!  It was very helpful... Almost working perfectly, but I have a followup question.

The code sets the display to "none" which just hides the context menu... Is there a way to set the style to make it look and act disabled?  I was examining how you do it with the toolbar, and it looks like there is a property called "unselectable" which is set to on or off... I am assuming that that is set via the setState method.  It also appears that you are dynamically bulding a grayscale version of whatever icon is displayed in the toolbar... You guys seriously thought about everything :)

Is there a way to do this to the contextMenu? 

I tried this to no avail.
menuItems[i].get_element().parentNode.attributes["unselectable"].value = "on";   
 

 

 

0
Dobromir
Telerik team
answered on 12 Apr 2010, 04:33 PM
Hi Michael,

By design, RadEditor does not provide this functionality. However you can try to manually cancel the click event by attaching a handler and executing $telerik.cancelRawEvent(e);

As an alternate solution to this problem, I would suggest you to replace the A element with a standard DIV element for the disabled ContextMenu item.

All the best,
Dobromir
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Editor
Asked by
Michael Pullella
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Michael Pullella
Top achievements
Rank 1
Share this question
or