PDA

View Full Version : Difference between el and body



aravindsastry
9 Oct 2012, 1:47 AM
Hi

I'm trying to understand the difference between binding option of listeners of a panel. Please let m eknow what exactly happens when the el property or body property is bound with the event w.r.t following code:

listeners: {
click: {
element: 'el', //bind to the underlying el property on the panel
fn: function(){ console.log('click el'); }
},
dblclick: {
element: 'body', //bind to the underlying body property on the panel
fn: function(){ console.log('dblclick body'); }
}
}


Thanks

mitchellsimoens
15 Oct 2012, 5:37 AM
They are different DOM elements. If you create a panel it will have a <div> at the top level of the Panel DOM which is the el. Below it you will have other <div>s for the header and the panel body.

aravindsastry
16 Oct 2012, 10:07 AM
Thank you mitchellsimoens. But I'm still unclear on its usage in a practical scenario. Lets say If I use el and listen to mouseover event and when I mouseover on panel body the function should not be called. Am I right? But this is not happening. Both el and body seems to have same effect. Can you please help me understand its practical relevance.

skirtle
16 Oct 2012, 10:38 AM
The el is the outermost element for the panel.

The body is one of the child elements.

Docked items like the panel's header are not inside the body but they are inside the el.

Keep in mind that events bubble (propagate) so an event that fires on the panel's body will also fire on the el unless the event's propagation is stopped.

For a concrete example of a difference, a mouseover listener registered on the body will not fire if you mouseover on the header. A mouseover listener registered on the el will fire for both the body and header.

mitchellsimoens
16 Oct 2012, 11:06 AM
Thank you mitchellsimoens. But I'm still unclear on its usage in a practical scenario. Lets say If I use el and listen to mouseover event and when I mouseover on panel body the function should not be called. Am I right? But this is not happening. Both el and body seems to have same effect. Can you please help me understand its practical relevance.

If you have a mouseover event on the el then when you move your mouse anywhere within the component it will fire. If you have a mouseover event on the body it will only fire on the body but if you mouse over the header (where the title is) it will not fire as the header isn't within the body but is within the el.