PDA

View Full Version : Ext.EventManager?



alejandroNNU
13 Mar 2014, 11:48 AM
Could someone please explain to me how Ext.EventManager works? I'm interested in it's onWindowResize() method, but I'm not sure how this works, where would I create the Ext.EventManager? and where would I call it's method? Let's say I wanted to call this simple function:


testFunction : function () {
console.log('hello world');
}

every time the window resizes, could someone do a quick example on how this would work using an EventManager please?

scottmartin
13 Mar 2014, 4:08 PM
You can track using the following:


Ext.EventManager.onWindowResize(myPanel.doLayout, myPanel);

alejandroNNU
13 Mar 2014, 4:26 PM
Hey Scott, and where would I put that code to start 'listening'? If I put it in say, an afterRender event for myPanel, will it start listening for a window resize after myPanel is rendered and continue listening from then on? I guess that was my main inquiry. I won't be back on my computer till tomorrow to test this which is why I wanted to ask, thank you for the help btw.

scottmartin
14 Mar 2014, 6:28 AM
You can place it after you define your container.



var myPanel = Ext.create(..);
Ext.EventManager.onWindowResize(myPanel.doLayout, myPanel);

skirtle
14 Mar 2014, 10:08 AM
You should also consider using removeResizeListener to remove the listener if your panel is destroyed.

If you want to keep the resize logic wrapped up in your panel class I see no reason not to use an afterRender override. Personally I think I'd override onBoxReady instead (it's called after the first layout is complete) but officially that's a private method, so you may prefer to stick with afterRender.

alejandroNNU
18 Mar 2014, 5:51 AM
works great, thanks scott and skirtle.