[Proto-Scripty] Re: Is stopObserving necessary?
Hi Simon, you should use event delmeguation so that, you first only set one observer, and then you can freely modify the DOM and still access to your event. -- david On 27 oct, 09:55, T.J. Crowder t...@crowdersoftware.com wrote: Hi Simon, ...do I need to stopObserving those events before replacing the elements. Yes, otherwise a variety of things do indeed sit around in memory. HTH, -- T.J. Crowder Independent Software Consultant tj / crowder software / comwww.crowdersoftware.com On Oct 26, 7:07 pm, Simon simon.hagst...@gmail.com wrote: If I observe events on elements that I later replace with new elements with innerHTML, do I need to stopObserving those events before replacing the elements. I guess I'm mostly concerned about memory leakage. E.g: div id=inputs input type=text name=input1 / ... input type=text name=input100 / /div $('inputs').select('input').invoke('observe', 'blur', function() {...}); $('inputs').innerHTML = 'input type=text name=input101 / ... input type=text name=input200 /'; $('inputs').select('input').invoke('observe', 'blur', function() {...}); Thanks Simon --~--~-~--~~~---~--~~ 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 prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Is stopObserving necessary?
Event delegation is indeed a wonderful thing. One thing to watch out for here though is that input blur, focus and form submit don't bubble (don't know if it's on all browsers, but certainly on some). There's NWEvents (http://javascript.nwbox.com/NWEvents/) that handles those special cases for you. We've used it to create a totally transparent (no initialization necessary) form validator. No need to observe forms, works with newly inserted ajax forms, no need to stop observing and only one observer, no matter how many form elements you have on the page, simply nothing to worry about anymore. On 30 Oct 2009, at 10:39, david wrote: you should use event delmeguation so that, you first only set one observer, and then you can freely modify the DOM and still access to your event. -- david On 27 oct, 09:55, T.J. Crowder t...@crowdersoftware.com wrote: Hi Simon, Yes, otherwise a variety of things do indeed sit around in memory. On Oct 26, 7:07 pm, Simon simon.hagst...@gmail.com wrote: If I observe events on elements that I later replace with new elements with innerHTML, do I need to stopObserving those events before replacing the elements. I guess I'm mostly concerned about memory leakage. E.g: div id=inputs input type=text name=input1 / ... input type=text name=input100 / /div $('inputs').select('input').invoke('observe', 'blur', function() {...}); $('inputs').innerHTML = 'input type=text name=input101 / ... input type=text name=input200 /'; $('inputs').select('input').invoke('observe', 'blur', function() 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 prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Is stopObserving necessary?
Good catch Peter, my explanation was lacking ... explanation :)) btw, NWEvent is impressive, like NWMatcher: http://javascript.nwbox.com/NWMatcher/ I recommand using both ! -- david On 30 oct, 11:11, Peter De Berdt peter.de.be...@pandora.be wrote: Event delegation is indeed a wonderful thing. One thing to watch out for here though is that input blur, focus and form submit don't bubble (don't know if it's on all browsers, but certainly on some). There's NWEvents (http://javascript.nwbox.com/NWEvents/) that handles those special cases for you. We've used it to create a totally transparent (no initialization necessary) form validator. No need to observe forms, works with newly inserted ajax forms, no need to stop observing and only one observer, no matter how many form elements you have on the page, simply nothing to worry about anymore. On 30 Oct 2009, at 10:39, david wrote: you should use event delmeguation so that, you first only set one observer, and then you can freely modify the DOM and still access to your event. -- david On 27 oct, 09:55, T.J. Crowder t...@crowdersoftware.com wrote: Hi Simon, Yes, otherwise a variety of things do indeed sit around in memory. On Oct 26, 7:07 pm, Simon simon.hagst...@gmail.com wrote: If I observe events on elements that I later replace with new elements with innerHTML, do I need to stopObserving those events before replacing the elements. I guess I'm mostly concerned about memory leakage. E.g: div id=inputs input type=text name=input1 / ... input type=text name=input100 / /div $('inputs').select('input').invoke('observe', 'blur', function() {...}); $('inputs').innerHTML = 'input type=text name=input101 / ... input type=text name=input200 /'; $('inputs').select('input').invoke('observe', 'blur', function() 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 prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Is stopObserving necessary?
Hi Simon, ...do I need to stopObserving those events before replacing the elements. Yes, otherwise a variety of things do indeed sit around in memory. HTH, -- T.J. Crowder Independent Software Consultant tj / crowder software / com www.crowdersoftware.com On Oct 26, 7:07 pm, Simon simon.hagst...@gmail.com wrote: If I observe events on elements that I later replace with new elements with innerHTML, do I need to stopObserving those events before replacing the elements. I guess I'm mostly concerned about memory leakage. E.g: div id=inputs input type=text name=input1 / ... input type=text name=input100 / /div $('inputs').select('input').invoke('observe', 'blur', function() {...}); $('inputs').innerHTML = 'input type=text name=input101 / ... input type=text name=input200 /'; $('inputs').select('input').invoke('observe', 'blur', function() {...}); Thanks Simon --~--~-~--~~~---~--~~ 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 prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---