Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Is there a way to capture right-click on a node in ImageMap mode? (Read 2987 times)
jlj30
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 183
Joined: Sep 4th, 2011
Is there a way to capture right-click on a node in ImageMap mode?
Jul 26th, 2012 at 4:22pm
Print Post  
Hi,

I'd like to implement a contextual menu on the right-click of a node.
Is there any way to accomplish this in ImageMap mode?

Thanks in advance for any suggestions.

Jim
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Is there a way to capture right-click on a node in ImageMap mode?
Reply #1 - Jul 27th, 2012 at 10:08am
Print Post  
Hi Jim,

There is the NodeClicked client event, but unfortunately it is raised only for left-button clicks.
As a workaround you can use the DiagramView CreatingAreaElement server side event, which you could handle to pass a custom attribute to the created node on the client - for example, you could attach a mousedown client event handler. Then handle the event on the client to show a context menu at the cursor.

If you need to suppress the browser's own built-in context menu, handle the body.oncontextmenu event and return false:
Code (HTML)
Select All
 <body oncontextmenu="return false;">  



You can check out our Menu control from the ASP.NET Pack release: http://www.mindfusion.eu/ui-webforms-pack.html#menu to use as a context menu. Set the orientation to Vertical and place it in a hidden DIV element. With it you can create something like this:


These are some code snippets that can help you to achieve this
Code
Select All
void DiagramView1_CreatingAreaElement(object sender, MindFusion.Diagramming.WebForms.CreatingAreaElementEventArgs e)
{
  // Attach the mousedown event handler
  e.Attributes["onmousedown"] = "return onNodeMouseDown(event)";
}
 


Code (HTML)
Select All
<!-- Register the MindFusion.UI.Web assembly to use the Menu control -->
<%@ Register Assembly="MindFusion.UI.Web" Namespace="MindFusion.UI.Web" TagPrefix="ui" %>

<!-- omitted code... -->

<!-- Set up the Menu -->
<div id="contextMenuContainer" style="display: none;">
  <!-- The Menu control -->
  <ui:Menu ID="Menu1" runat="server" Orientation="Vertical" Theme="Silver" ItemClickedScript="onMenuItemClick" ShowTrail="true">
    <ui:MenuItem Title="Action 1">
      <ui:MenuItem Title="Sub Action 1.1" />
      <ui:MenuItem IsSeparator="True" />
      <ui:MenuItem Title="Sub Action 1.2"/>
    </ui:MenuItem>
    <ui:MenuItem Title="Action 2" />
  </ui:Menu>
</div>
 



Code (Javascript)
Select All
/**
* Handle the mousedown event to show the menu container
*/
function onNodeMouseDown(e)
{
  if (e.button == 2 /* for right click */)
  {
    // show the context menu and place it at the mouse cursor
    var ctxmenu = $get('contextMenuContainer');
	if (ctxmenu)
	{
	  // This may be not enough, and some addtional processing
	  // for determining the location to place the element may be required.
	  Sys.UI.DomElement.setLocation(ctxmenu, e.clientX, e.clientY);

	  ctxmenu.style.display = 'block';
    }
  }
}

/**
* Handle the Menu.ItemClicked client event to respond
* when a user clicks on a MenuItem and then hide the menu again.
*/
function onMenuItemClick(sender, args)
{
  // Process the clicked item
  // ...........

  // hide the context menu.
  var ctxmenu = $get('contextMenuContainer');
  if (ctxmenu)
  {
    ctxmenu.style.display = 'none';
  }
}
 



I hope you'll find this helpful.

Regards,
Lyubo
  
Back to top
 
IP Logged
 
jlj30
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 183
Joined: Sep 4th, 2011
Re: Is there a way to capture right-click on a node in ImageMap mode?
Reply #2 - Jul 27th, 2012 at 12:33pm
Print Post  
Hi,

Great response.
Thanks for all of the code snippets.
This is more than I was expecting.
I'll try it out.

Jim
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint