xibnoe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jan-17 05:26 UTC
Any things worng with this code??
RegisterEvent:function(){ document.getElementsByClassName(''manage'').each( function(element){ var act=TMS.Event.ShowPopup.bindAsEventListener(element); Event.observe(element, ''click'',act) } ); }, UnregisterEvent:function(){ document.getElementsByClassName(''manage'').each( function(element){ var act=TMS.Event.ShowPopup.bindAsEventListener(element); Event.stopObserving(element, ''click'', act) } ); }, when i call registerEvent,.. its work but Unregister event dont work.. any idea? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
xibnoe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> ... > var act=TMS.Event.ShowPopup.bindAsEventListener(element); > Event.stopObserving(element, ''click'', act) > ... > when i call registerEvent,.. its work but Unregister event dont work.. > any idea? >"act" is not the same both times. bindAsEventListener() returns a new function each time you call it. see http://prototypejs.org/api/event/stopObserving You''ll need to save the bound function somewhere so that you can detach it later. - Ken Snyder --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
xibnoe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jan-18 07:27 UTC
Re: Any things worng with this code??
sorry i dont understand what u mean :( can u give me a litle example? did you mean save every TMS.Event.ShowPopup.bindAsEventListener(element); on array? On Jan 17, 10:23 pm, Ken Snyder <kendsny...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> xib...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > ... > > var act=TMS.Event.ShowPopup.bindAsEventListener(element); > > Event.stopObserving(element, ''click'', act) > > ... > > when i call registerEvent,.. its work but Unregister event dont work.. > > any idea? > > "act" is not the same both times. bindAsEventListener() returns a new > function each time you call it. seehttp://prototypejs.org/api/event/stopObserving > > You''ll need to save the bound function somewhere so that you can detach > it later. > > - Ken Snyder--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
xibnoe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> sorry i dont understand what u mean :( > can u give me a litle example? > did you mean save every > TMS.Event.ShowPopup.bindAsEventListener(element); on array? >Yes: RegisterEvent: function() { this.listeners = []; document.getElementsByClassName(''manage'').each( function(element) { var act = TMS.Event.ShowPopup.bindAsEventListener(element); this.listeners.push([element, act]); Event.observe(element, ''click'', act) }, this ); }, UnregisterEvent: function() { this.listeners.each(function(pair) { var element = pair[0], act = pair[1]; Event.stopObserving(element, ''click'', act); }); } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---