[Proto-Scripty] Re: delegating the event on document
On 18 Sep 2008, at 16:30, Ken Snyder wrote: A question, does the focus effect bubble ?? because this work: $(document.body).observe('click', function(e) { var _elem=Event.element(e); alert(_elem.tagName); return; }); but not the same code when you use the focus event instead of the click event works. -- david That is correct. The focus event does not bubble. (http://www.sitepoint.com/blogs/2008/07/23/javascript-event-delegation-is-easier-than-you-think/ ). The article mentions you should not use event delegation for focus, blur, load, unload, or mousemove. We're using event delegation for form validation and tooltips (so using blur/focus/submit, three non-bubbling events) with NWEvents: http://code.google.com/p/nwevents/ Works perfectly btw and has no Prototype incompatibilities. Example at http://javascript.nwbox.com/NWEvents/delegates.html Best regards Peter De Berdt --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: delegating the event on document
Hi Rauan, A question, does the focus effect bubble ?? because this work: $(document.body).observe('click', function(e) { var _elem=Event.element(e); alert(_elem.tagName); return; }); but not the same code when you use the focus event instead of the click event works. -- david On 18 sep, 13:15, Rauan Maemirov [EMAIL PROTECTED] wrote: I'm using 2nd example. Just thought, that 1st would be more elegant. :)) But if I'll add link dynamically, it will not blur in 2nd example. On Sep 18, 5:02 pm, bluezehn [EMAIL PROTECTED] wrote: Why can't you just use the 2nd example? Semantically that's a lot better, as you want to really observe each link, not the whole body. I mean, the first example is saying, Observe a focus to the body. That's not really helping at all with the focus of any specific link, if you see what I mean. On Sep 18, 11:51 am, Rauan Maemirov [EMAIL PROTECTED] wrote: It's very simple to do for some html object as ancestor, but not for whole body. What I'm doing wrong? $(document.body).observe('focus', function(e) { if (!(elem = e.findElement('a'))) return; elem.blur(); }); The main aim is to avoid effect of wrapping the link, when clicking on it. This code works fine: $$('a').invoke('observe', 'focus', linkBlur); function linkBlur(e) { elem = e.element(); elem.blur(); } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: delegating the event on document
Hmm, it's strange. Because your code works fine. But, if I change it to $(document.body).observe('focus', function(e) { var _elem=Event.element(e); alert(_elem.tagName); return; }); it doesn't work. On Sep 18, 5:43 pm, david [EMAIL PROTECTED] wrote: Hi Rauan, A question, does the focus effect bubble ?? because this work: $(document.body).observe('click', function(e) { var _elem=Event.element(e); alert(_elem.tagName); return; }); but not the same code when you use the focus event instead of the click event works. -- david On 18 sep, 13:15, Rauan Maemirov [EMAIL PROTECTED] wrote: I'm using 2nd example. Just thought, that 1st would be more elegant. :)) But if I'll add link dynamically, it will not blur in 2nd example. On Sep 18, 5:02 pm, bluezehn [EMAIL PROTECTED] wrote: Why can't you just use the 2nd example? Semantically that's a lot better, as you want to really observe each link, not the whole body. I mean, the first example is saying, Observe a focus to the body. That's not really helping at all with the focus of any specific link, if you see what I mean. On Sep 18, 11:51 am, Rauan Maemirov [EMAIL PROTECTED] wrote: It's very simple to do for some html object as ancestor, but not for whole body. What I'm doing wrong? $(document.body).observe('focus', function(e) { if (!(elem = e.findElement('a'))) return; elem.blur(); }); The main aim is to avoid effect of wrapping the link, when clicking on it. This code works fine: $$('a').invoke('observe', 'focus', linkBlur); function linkBlur(e) { elem = e.element(); elem.blur(); } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: delegating the event on document
david wrote: Hi Rauan, A question, does the focus effect bubble ?? because this work: $(document.body).observe('click', function(e) { var _elem=Event.element(e); alert(_elem.tagName); return; }); but not the same code when you use the focus event instead of the click event works. -- david That is correct. The focus event does not bubble. (http://www.sitepoint.com/blogs/2008/07/23/javascript-event-delegation-is-easier-than-you-think/). The article mentions you should not use event delegation for focus, blur, load, unload, or mousemove. - Ken Snyder --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---