This is a migrated thread and some comments may be shown as answers.
context menu for A
5 Answers 5 Views
This is a migrated thread and some comments may be shown as answers.
hepek
Top achievements
Rank 1
hepek asked on 19 Feb 2020, 04:02 PM

I have a right-click menu like this:

<telerik:EditorContextMenu TagName="A">
      <telerik:EditorTool Name="Hyperlink Properties"/>
</telerik:EditorContextMenu>

when I right click on a link I get my custom popup window.

I would like to have different context menu for hyperlinks and bookmarks.
is this even possible?

thank you

 


5 Answers, 1 is accepted

Sort by
0
hepek
Top achievements
Rank 1
answered on 19 Feb 2020, 04:27 PM

*to be more precise, 

- if user clicks on hyperlink I would like to show right-menu item "Hyperlink Properties" (this is already working for me)
- if user clicks on Bookmark I would like to show "Bookmark Properties" 

* the diff between bookmark and hyperlink is bookmark has "name" attribute, and it is missing href attribute.

 

0
Rumen
Telerik team
answered on 24 Feb 2020, 11:28 AM

Hi Nermin,

You can use the oncontextmenu client event to attach to the context menu event of RadEditor and check for the name attribute of the A tag in a similar way as it is shown in the example for IMG tag provided at Custom Context Menus:

<style>
    .bookmark { border: 1px solid red; }
</style>
<script type="text/javascript">  
function CallContextMenu(editor)   
{   
    editor.attachEventHandler ("oncontextmenu", function (e)   
    {     
        var oSelection = editor.getSelectedElement();  
        if(oSelection.tagName.toLowerCase() == "a") 
        { 
            if (oSelection.getAttribute("name")) 
            { 
                alert("the selected element className is " + oSelection.className); 
                alert("the 'e' argument returns the mouse position " + e);  
                alert("get a reference to the editor's body " + editor.get_document().body);  
                alert("the selected element is " + oSelection.tagName);  

                
                $telerik.cancelRawEvent(e);  
                return false; //disable the browser's context menu     
                
            } 
            
        } 
    });  
}   
</script>  
  
<telerik:RadEditor ID="RadEditor1" runat="server" OnClientLoad="CallContextMenu">  
  <Content> 
    <a name="bookmark" class="bookmark">Bookmark<//a>
  </Content> 
</telerik:RadEditor> 

Regards,
Rumen
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
hepek
Top achievements
Rank 1
answered on 24 Feb 2020, 07:44 PM

thank you Rumen. you are the best. but how do I show different popup text based on link?

when user right-clicks on hyperlink currently the popup menu reads "Hyperlink Properties"
same happens if the right-click on bookmark.

I want to display a different popup menu for bookmark that reads "Bookmark properties", rather than "Hyperlink Properties"
I probably need to intercept the right-click menu and dynamically change the text shown. is that even possible?

 

thank you

0
hepek
Top achievements
Rank 1
answered on 24 Feb 2020, 07:52 PM

another question. my right-click menu on link looks like this:

- Add Comment
- Hyperlink Properties
- Remove Hyperlink

how can I remove the first option (Add Comment)?

thank you

 

0
Rumen
Telerik team
answered on 27 Feb 2020, 12:41 PM

Hi Nermin,

Thank you for the nice words!

There is a code library of how to programmatically changing the context menu depending on the selection: 

Changing context menu programmatically client-side. The sample provided there will help you implement your scenario via the provided ability to get access to the context menu and manage its items.

As for removing items from the built-in context menus please check out this article: Context Menus Overview. It shows how to predefine the default context menus.

 

Regards,
Rumen
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
Asked by
hepek
Top achievements
Rank 1
Answers by
hepek
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or