[Proto-Scripty] Re: Question regarding Element.observe and Element.stopObserving
Yeah. I know. I did that: Element.addMethods({ clearEvents: function(element) { element.descendants().each( function(obj){ if (obj._prototypeEventID) { obj.stopObserving(); } } ); element.stopObserving(); return element; } }); I just dont like to extend core features as it makes hard to upgrade to newer verions later. Thanks for your answer. ;) []'s Labs 2008/10/2 puckpuck [EMAIL PROTECTED] This exact question was asked today at TAE. At this time, no. stopObserving will not go through the children of the container and remove events. In the future it is certainly possible. Mind you it wouldn't be very difficult to write your own method to recurse through all the children of a given element, and call stopObserving on those children. var elem = $(myElement); elem.stopObserving() elem.select(*).invoke(stopObserving); On Oct 1, 11:02 am, labs2.0 [EMAIL PROTECTED] wrote: Hi. Please, would you be kind to clearify this to me: if I call Event.stopObserving(myWindow), beeing 'myWindow' a div (ajax generated window wich can came and go as the user will), who doesnt have observers, but its a container (and parent) for many other elements (components) that may does, may doesn't have observers, will this call work recursivelly? If dont, why??? Assuming it doesnt, and that prototype beautifully make things in a clean and natural way, should'nt we espect some behaviour like that? I mean, in a large framework, where I create a window with many comps, one could say that its my job to create a event garbage collector (which I did hacking prototype 1.5.0) to clean up things when, say, a window pops out, but then again, if I already have a nice way to setup events, its ask too much to have a nice one to get rid off of all of them too? :) In prototype 1.5.0 I've hacked a Event.observeFor(container, element, event) and a Event.unloadContainer(container); for memory sake. Am I missing something new (and cool) about Events here? Thank you and let me be +1 to say that prototype ROCKS!! []'s Labs On 10 set, 09:38, 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 giveneventname on the given element will be removed. This is quite handy. Even better, if you leave off theeventname 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 stopeventobserve: 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 alleventfrom 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
[Proto-Scripty] Re: Question regarding Element.observe and Element.stopObserving
Yeah, but if you firebug the Event object after recursive unregister, you will see that every element that doesnt had a _prototypeEventID will create an entry in Event.cache. This is because the way the eventId is generated and THERE I'll not mess with :) Those entry are empty, I know, but ohhh... its damn ugly. ;) P.s. agreed with the 'stopObservingNested' thing. []'s Labs 2008/10/2 puckpuck [EMAIL PROTECTED] When I made that post, I was very groggy, and realized I used a CSS selector *, which well... is horrid slow, especially on IE. using elem.descendants() instead would of made far more sense. Also I would stay away from checking on the existing of _prototypeEventID on the element. This is an internal prototype property, which can change at any time. Relying on such a property can be dangerous when you attempt to do an upgrade, even a small, bug fix one. The stopObserving method, will check the internal prototype registry for events, which is very fast, and recommended. On Oct 2, 9:03 am, Lea Hayes [EMAIL PROTECTED] wrote: Hi puckpuck!, That's a really handy little snippet, so much simpler than manually enumerating nested HTML elements and stopping them individually (which I have previously done). If this functionality were to be bundled within the Prototype framework I personally think it would be better to offer an additional method (i.e. stopObservingNested or the like). Otherwise, the stopObserving method could cause undesirable effects, like if nested events are still wanted. Thanks! Lea Hayes 2008/10/2 puckpuck [EMAIL PROTECTED]: This exact question was asked today at TAE. At this time, no. stopObserving will not go through the children of the container and remove events. In the future it is certainly possible. Mind you it wouldn't be very difficult to write your own method to recurse through all the children of a given element, and call stopObserving on those children. var elem = $(myElement); elem.stopObserving() elem.select(*).invoke(stopObserving); On Oct 1, 11:02 am, labs2.0 [EMAIL PROTECTED] wrote: Hi. Please, would you be kind to clearify this to me: if I call Event.stopObserving(myWindow), beeing 'myWindow' a div (ajax generated window wich can came and go as the user will), who doesnt have observers, but its a container (and parent) for many other elements (components) that may does, may doesn't have observers, will this call work recursivelly? If dont, why??? Assuming it doesnt, and that prototype beautifully make things in a clean and natural way, should'nt we espect some behaviour like that? I mean, in a large framework, where I create a window with many comps, one could say that its my job to create a event garbage collector (which I did hacking prototype 1.5.0) to clean up things when, say, a window pops out, but then again, if I already have a nice way to setup events, its ask too much to have a nice one to get rid off of all of them too? :) In prototype 1.5.0 I've hacked a Event.observeFor(container, element, event) and a Event.unloadContainer(container); for memory sake. Am I missing something new (and cool) about Events here? Thank you and let me be +1 to say that prototype ROCKS!! []'s Labs On 10 set, 09:38, 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 giveneventname on the given element will be removed. This is quite handy. Even better, if you leave off theeventname 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
[Proto-Scripty] onExeption event only. Where's the problem?
Hi, I can't find the probles with code to save html table data. Can anybody help? I get onExeption event only. The code is below default.asp (Path www.comp.com/defailt.asp): == params='email=t...@comp.comUser=UserName' new Ajax.Request (Scripts/ajaxSaveBalance.asp', {method: 'post', postBody: params, onExeption: alert('Error')}); (I store ajaxSaveBalance.asp in www.comp.com/Scripts/ajaxSaveBalance.asp). Where's my problem with code? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---