Hi all, I'm using behaviour(.js) to add event handlers to all the table cells in a table (mouseover, mouseout, clickk). However, I'm also ditching the table and replacing it with an Ajax.Updater so I want to remove all the observers before I lose them. Unfortunately, the Event.observe calls were written as inline anonymous functions so, when calling Event.stopObserving, I'm supposed to pass in a reference to the observer function, but it isn't able to be referenced as far as I know. I'd use Event.unloadCache() as a brute-force solution, but there are a ton of other observers for other areas of the page that would all have to be re-created. Is there a way around this (keeping the 'observers' as anonymous functions), or a better way to approach this? (Why do these things always crop up the night before The Big Demo?) Many many thanks! -- Cam McVey cam.mcvey@gmail.com _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
It may or may not work, but you could try this: Event.stopObserving(element, element.onclick); Etc, etc, etc. The element.onclick *should* return the anonymous function ref, but it may not work in all browsers. You''d have to do that for each event and each element, though. Greg> -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org[mailto:rails-spinoffs-> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Cam McVey > Sent: Wednesday, January 18, 2006 12:23 PM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails-spinoffs] Event.stopObserving and anonymous functions > > Hi all, > > I''m using behaviour(.js) to add event handlers to all the table cells > in a table (mouseover, mouseout, clickk). However, I''m also ditching > the table and replacing it with an Ajax.Updater so I want to remove > all the observers before I lose them. Unfortunately, the Event.observe > calls were written as inline anonymous functions so, when calling > Event.stopObserving, I''m supposed to pass in a reference to the > observer function, but it isn''t able to be referenced as far as I > know. > > I''d use Event.unloadCache() as a brute-force solution, but there are a > ton of other observers for other areas of the page that would all have > to be re-created. > > Is there a way around this (keeping the ''observers'' as anonymous > functions), or a better way to approach this? > > (Why do these things always crop up the night before The Big Demo?) > > Many many thanks! > -- > > Cam McVey > cam.mcvey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Hi Greg, I'm using Firefox (1.5) and neither element.onclick nor element.click apprear to work. Anything else I could try? Many thanks, Cam On 1/18/06, Gregory Hill <Gregory_Hill@tni.com> wrote:> It may or may not work, but you could try this: > > Event.stopObserving(element, element.onclick); > > Etc, etc, etc. > > The element.onclick *should* return the anonymous function ref, but it > may not work in all browsers. You'd have to do that for each event and > each element, though. > > Greg >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs