PDA

View Full Version : Overriding getX and getY



himalpatel
26 Feb 2012, 9:39 PM
Does anyone knows how to override getX and getY method of Ext.Element class ?

Thanks
Himal

vietits
26 Feb 2012, 11:03 PM
Let try


Ext.Element.prototype.$getX = Ext.Element.prototype.getX; // save the current getX
Ext.Element.prototype.getX = function(){
// your code here
// this.$getX.apply(this, arguments); <- call original getX
// return returnValue;
}

himalpatel
26 Feb 2012, 11:14 PM
Thanks for the code, I tried it but still it's calling the original function and not the one that i modified.
Here is the code that i used.

Ext.Element.prototype.$getX = Ext.Element.prototype.getX; // save the current getX
Ext.Element.prototype.getX = function(){
if(el!=null)
return ELEMENT.getXY(el)[0];
}

not sure what i am doign wrong. I just want to add if condition in the function.

Thanks
Himal

vietits
26 Feb 2012, 11:23 PM
How do you call getX()? It seems that you use Ext.Element.getX(el), don't you? If so you can override the Ext.Element.getX() as follow:


Ext.Element.getX = function(el){
var ret = null;
if(el != null){
ret = this.getXY(el)[0];
}
return ret;
}

himalpatel
27 Feb 2012, 12:08 AM
You got it right. I am using Ext.Element.getX(el). I tried the code that you mentioned but still it keeps on calling the old method. the method get called by Sencha internally. like if i minimize the browser window and maximize this method gets called. I have some instances while this method throws error because el is null and i want to handle that. there are other methods as well to override but i think if i can make it work for this rest should be easy.

Thanks
Himal