Hi again folks, It was already there, ticket #158 from June 10th: http://prototype.lighthouseapp.com/projects/8886/tickets/158
More on the new event stuff in 1.6.0: http://prototypejs.org/2007/8/15/prototype-1-6-0-release-candidate HTH, -- T.J. Crowder tj / crowder software / com On Sep 10, 1:38 pm, "T.J. Crowder" <[EMAIL PROTECTED]> wrote: > Hi folks, > > > try a look at the API > > documentation:http://www.prototypejs.org/api/event/stopObserving > > (you exactly do what is wrong !!) > > Actually, David, what she's doing is just fine. She's using a > new(ish) feature of stopObserving which appears to be missing from the > docs. If you don't include a handler in the stopObserving call, ALL > events hooked up by observe() for the given event name on the given > element will be removed. This is quite handy. Even better, if you > leave off the event name as well, stopObserving() will unhook all of > the handlers for that element [that were set up by observe()] > entirely. > > So this would be wrong: > > Event.observe(myelement, 'click', > this.clickHandler.bindAsEventListener(this)); > ... > Event.stopObserving(myelement, 'click', > this.clickHandler.bindAsEventListener(this)); > > because the function arguments don't match. > > But this is fine: > > Event.observe(myelement, 'click', > this.clickHandler.bindAsEventListener(this)); > ... > Event.stopObserving(myelement, 'click'); > > It removes *all* click handlers hooked using observe() from the > element. > > And this is fine: > > Event.observe(myelement, 'click', > this.clickHandler.bindAsEventListener(this)); > ... > Event.stopObserving(myelement); > > It removes *all* handlers for all events hooked using observe() from > the element. Great for when you're about to remove the element. > > I'll see if there's a doc ticket in Lighthouse for this and add one if > there isn't. > -- > T.J. Crowder > tj / crowder software / com > > On Sep 10, 12:14 pm, david <[EMAIL PROTECTED]> wrote: > > > Hi Lea, > > > try a look at the API > > documentation:http://www.prototypejs.org/api/event/stopObserving > > (you exactly do what is wrong !!) > > > Because you should do: > > > myTestClass.myCallback=this.clickHandler.bindAsEventListener(this); > > > myTestClass.prototype.initEvents = function() > > { > > var myDiv1 = $('exampleDiv1'); > > myDiv1.observe('click',myTestClass.myCallback); > > > } > > > And to stop event observe: > > > myTestClass.prototype.clearEvents = function() > > { > > var myDiv1 = $('exampleDiv1'); > > myDiv1.stopObserving('click',myTestClass.myCallback); > > > } > > > But we are from the original question which is if we could > > stopObserving all event from one element? > > The response is NO (otherwise, let me know, it save a lot of time and > > efforts sometime). > > > -- > > david > > > On Sep 2, 8:41 pm, Kruncher <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > I have just found out about the Prototype framework and am somewhat > > > impressed by how much simpler it makes things. I have found that using > > > the observe and stopObserving functions has eliminated a pretty major > > > memory leak within my scripts. > > > > Below is a snippet of my code (which appears to function correctly > > > with Prototype 1.6), but I just wanted to confirm that this is in fact > > > correct. From the user documentation it says that the stopObserving > > > method should be called in practically the same way as the observe > > > method. However, I want to make sure that ALL handlers are stopped for > > > a particular event of a particular element. > > > > // Called when object is initialized. > > > myTestClass.prototype.initEvents = function() > > > { > > > var myDiv1 = $('exampleDiv1'); > > > myDiv1.observe('click', > > > myTestClass.clickHandler.bindAsEventListener(this));} > > > > // Called whenever an object is destroyed. > > > myTestClass.prototype.clearEvents = function() > > > { > > > var myDiv1 = $('exampleDiv1'); > > > myDiv1.stopObserving('click'); // Is this line acceptable > > > to stop ALL click events for myDiv1? > > > > } > > > > Many thanks, > > > Lea Hayes > > --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] 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 -~----------~----~----~----~------~----~------~--~---
