PDA

View Full Version : Manipulating an existing ext component



lacco
23 Jun 2009, 12:32 PM
Hi!

I would like to add some default behavior to all tab panel's context menu events. Is there any way to do this by manipulating the Ext.TabPanel class without doing a "regular" extension (using Ext.ux.MyNewTabPanel = Ext.extend(Ext.TabPanel, {}))? I would need something like this:


Ext.TabPanel.prototype.afterInit = function(tabPanel){
tabPanel.on('contextmenu', function(){do sth.});
}Thx!

lacco
23 Jun 2009, 3:54 PM
Okay, I just have a first idea:



AnyNs.oldTabPanelInitComponent = Ext.TabPanel.prototype.initComponent;

Ext.override(Ext.TabPanel, {
initComponent: function(){
// Sets correct scope to oldInitComponent
AnyNs.oldTabPanelInitComponent.defer(0, this);

// Do anything I want here!
this.on('contextmenu', function(){do sth.});
}
});This is quite hacky because I just save the reference to the old function and call it later on. Do you know any nicer alternative?

evant
23 Jun 2009, 8:27 PM
If you're extending it, you would have a reference to the superclass:



MyTabs = Ext.extend(Ext.TabPanel, {
initComponent: function(){
// Sets correct scope to oldInitComponent
MyTabs.superclass.initComponent.call(this);

// Do anything I want here!
this.on('contextmenu', function(){do sth.});
}
});

lacco
23 Jun 2009, 11:13 PM
Yes, of course. But I don't want to replace all TabPanels within my Code, if there is any way to avoid this...

evant
23 Jun 2009, 11:20 PM
The way you had it is probably the most clear.

lacco
24 Jun 2009, 12:24 AM
Okay, here is my final version, just without saving a reference explicitly:


Ext.override(Ext.TabPanel, {
initComponent: Ext.TabPanel.prototype.initComponent.createSequence(function(){
// Do anything I want here!
this.on('contextmenu', function(){do sth.});
})
});