PDA

View Full Version : conetxt menu for the hole page



Richie1985
23 Apr 2013, 11:47 PM
hi, i want to use something like that:



Ext.getBody().on("contextmenu",
function(e){
console.log(e);
var menu = Ext.create('Ext.menu.Menu', {
width: 100,
height: 100,
margin: '0 0 10 0',
floating: true, // usually you want this set to True (default)
renderTo: Ext.getBody(), // usually rendered by it's containing component
items: [{
text: 'regular item 1'
},{
text: 'regular item 2'
},{
text: 'regular item 3'
}]
}).showAt(e.getXY());;

}, null, {preventDefault: true});


But the menu is not shown :(

can you help me?

slemmon
25 Apr 2013, 1:49 PM
Your code works for me in ExtJS 4.2.
Are you sure you're clicking on the body? You have content on the page in the body by chance?

Richie1985
26 Apr 2013, 3:19 AM
yes, i have content on the body (a viewport).

i want to have a context menu dont matter wher i make a right click...

slemmon
26 Apr 2013, 12:37 PM
The following code works fine for me (your code + a viewport) in ExtJS 4.2 on Chrome. It shows the context menu right where I right-click as expected.



Ext.widget('viewport');


Ext.getBody().on("contextmenu", function (e) {
console.log(e);
var menu = Ext.create('Ext.menu.Menu', {
width: 100,
height: 100,
margin: '0 0 10 0',
floating: true, // usually you want this set to True (default)
renderTo: Ext.getBody(), // usually rendered by it's containing component
items: [{
text: 'regular item 1'
}, {
text: 'regular item 2'
}, {
text: 'regular item 3'
}
]
}).showAt(e.getXY());;


}, null, {
preventDefault: true
});

Richie1985
26 Apr 2013, 10:54 PM
now my complete code is:


Ext.onReady(

function(){

Ext.widget('viewport');

Ext.getBody().on("contextmenu", function (e) {
console.log(e);
var menu = Ext.create('Ext.menu.Menu', {
width: 100,
height: 100,
margin: '0 0 10 0',
floating: true, // usually you want this set to True (default)
renderTo: Ext.getBody(), // usually rendered by it's containing component
items: [{
text: 'regular item 1'
}, {
text: 'regular item 2'
}, {
text: 'regular item 3'
}
]
}).showAt(e.getXY());;


}, null, {
preventDefault: true
});
});

but when i right click i see the console output and after that i see this error in firebug:

TypeError: container is undefined
me.container = container.dom ? container : Ext.get(container);

slemmon
27 Apr 2013, 10:51 PM
It work for me on Chrome using ExtJS 4.2. What browser and ExtJS library version are you using?

Richie1985
28 Apr 2013, 10:43 PM
i use firefox newest version and ext-4.2.0.663

slemmon
7 May 2013, 11:27 AM
Worked for me just now in FF 20.0.1 in OSX and Win7.
Sorry I couldn't be more help.

Uninstall / reinstall FF?