PDA

View Full Version : How to capture mouse rightclick?



pyr0l0
24 Nov 2007, 3:39 PM
Hi to all. Is any way to capture mouse rightclick on a tree? I need to capture that event to focus a node and show the context menu only clicking right mouse button. Is it possible??

efege
24 Nov 2007, 3:47 PM
As in the left "Feeds" panel in the Feed Viewer 3 example (http://extjs.com/deploy/dev/examples/feed-viewer/view.html)?

pyr0l0
24 Nov 2007, 3:51 PM
Yes, How can i do this?

efege
24 Nov 2007, 3:58 PM
Studying the code in the examples/feed-viewer folder, particularly FeedPanel.js. This wiki page (http://extjs.com/learn/User:Efege:FeedViewer3) may also help you.

pyr0l0
24 Nov 2007, 4:14 PM
Thanks a lot, i study FeedPanel.js now.

pyr0l0
25 Nov 2007, 2:30 AM
I cant see where capture mouse right mouse click. Can anybody help me? plssss

wm003
25 Nov 2007, 3:48 AM
Try something like


element = Ext.get('myelement');
element.on({
'contextmenu' : function() {
alert('You clicked the right mousebutton on me');
},
scope: this
});

pyr0l0
25 Nov 2007, 4:25 AM
And where try that code?

wm003
25 Nov 2007, 4:47 AM
Where? Somewhere in your script ofcourse :)

Do some HTML-markup including a div-container with the id "myelement" an then run this js-code.

Try this



<html>
<head>
<link rel="stylesheet" type="text/css" href="js/extjs/resources/css/ext-all.css">
<script type="text/javascript" src="js/extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="js/extjs/ext-all-debug.js"></script>
<script type="text/javascript">

Ext.onReady(function(){
element = Ext.get('myelement');
element.on({
'contextmenu': function() {
Ext.Msg.alert('Rightclick Listener','you rightclicked on me');
},
scope:this
});
});

</script>
</head>
<body oncontextmenu="return false;">
<div id="myelement">Right Click on me</div>
</body>
</html>

mw-flow
28 Dec 2007, 1:45 AM
Thanks all for your code examples. It might be worth adding that, in most cases when you need to handle the rightclick, the browser-specific context menu should NOT appear. In that case, just add preventDefault:true as a paramter when adding the contextmenu listener:


element.on({
'contextmenu': function() {
Ext.Msg.alert('Rightclick','you rightclicked on me');
},
scope:this,
preventDefault:true
});

This prevents the browser-specific context menu from appearing after you right-clicked.

Regards
mw-flow

mariposil
7 Jan 2008, 11:53 AM
make it work like this:

myelement.on({
'contextmenu': function(e)
{
Ext.Msg.alert('Rightclick Listener','you rightclicked on me');
e.preventDefault();
},
scope:this
});

redlz2500
25 Jan 2008, 5:50 AM
Studying the code in the examples/feed-viewer folder, particularly FeedPanel.js. This wiki page (http://extjs.com/learn/User:Efege:FeedViewer3) may also help you.
thanks you!!
i just study the simple examples recently
but didn't find what i want

your post help me to solve my problem
thanks

rstanley
8 Feb 2008, 12:21 PM
make it work like this:

myelement.on({
'contextmenu': function(e)
{
Ext.Msg.alert('Rightclick Listener','you rightclicked on me');
e.preventDefault();
},
scope:this
});

Thanks mariposil!!!!

Your code is successfully!
Regards