context menu for A

6 posts, 0 answers
  1. hepek
    hepek avatar
    8 posts
    Member since:
    Feb 2020

    Posted 19 Feb Link to this post

    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

     


  2. hepek
    hepek avatar
    8 posts
    Member since:
    Feb 2020

    Posted 19 Feb Link to this post

    *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.

     

  3. Rumen
    Admin
    Rumen avatar
    14324 posts

    Posted 24 Feb Link to this post

    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.
  4. hepek
    hepek avatar
    8 posts
    Member since:
    Feb 2020

    Posted 24 Feb in reply to Rumen Link to this post

    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

  5. hepek
    hepek avatar
    8 posts
    Member since:
    Feb 2020

    Posted 24 Feb in reply to Rumen Link to this post

    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

     

  6. Rumen
    Admin
    Rumen avatar
    14324 posts

    Posted 27 Feb Link to this post

    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.
Back to Top