Just wondering why Event.stopObserving() doesn''t remove the itself from the Event.obervers array? Is there a reason for this? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Eric Harrison
2006-Dec-14 10:27 UTC
Re: Should Event.stopObserving() remove itself from cache?
Event.observers (to the best of my knowledge) merely exists to fix an IE memory leak. 2158 /* prevent memory leaks in IE */ 2159 if (navigator.appVersion.match(/\bMSIE\b/)) 2160 Event.observe(window, ''unload'', Event.unloadCache, false); The only reason that any events are put into Event.observers is so when the unload event fires for the window object prototype.js can quickly spin through an entire list of events that WERE observed to remove the reference (and prevent a potential circular reference that IE''s garbage collector will miss). Basically, Event.observers is a ''behind-the-scenes'' type of element and you really don''t even need to worry about it at all. It''s tempting to want to keep Event.observers clean and up to date with your current observational model, but this is a mistake and will just end up being a frustration in the long run. -E On 12/13/06, heidmotron <matthew.heidemann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Just wondering why Event.stopObserving() doesn''t remove the itself from > the Event.obervers array? > > Is there a reason for this? > > > > >-- Eric Ryan Harrison --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
heidmotron
2006-Dec-14 19:11 UTC
Re: Should Event.stopObserving() remove itself from cache?
I get the Event.unloadCache but let''s say you have something like this: <div id="test"> </div> script is: Event.observe(''test'', ''click'', function(){ alert(''I am so happy'') }) Your Event.observers.length is 1 then you want to remove test, so before you actually remove it from the dom you are kind enough to say, "hey, test div, stop observing that click and go have a beer" Event.stopObserving(''test'', ''click'', function(){ alert(''I am so happy'') }) You would think that observer would have beer and get out of the Event.observers array so length would equal Zero. But it doesn''t, so I complain. So now the Event.unloadCache() cycles through observer objecst that don''t exist anymore which doesn''t seem right. Also, I don''t think that hard to fix just put after line element.removeEventListener(name, observer, useCapture); this.observers.pop([element, name, observer, useCapture]); and element.detachEvent(''on'' + name, observer); this.observers.pop([element, name, observer, useCapture]); Just my 2 cents.> Basically, Event.observers is a ''behind-the-scenes'' type of element > and you really don''t even need to worry about it at all. It''s tempting > to want to keep Event.observers clean and up to date with your current > observational model, but this is a mistake and will just end up being > a frustration in the long run. > > -E > > On 12/13/06, heidmotron <matthew.heidem...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Just wondering why Event.stopObserving() doesn''t remove the itself from > > the Event.obervers array? > > > Is there a reason for this?-- > Eric Ryan Harrison--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Martin Bialasinski
2006-Dec-14 20:16 UTC
Re: Should Event.stopObserving() remove itself from cache?
On 12/14/06, heidmotron <matthew.heidemann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> script is: > Event.observe(''test'', ''click'', function(){ alert(''I am so happy'') }) > > Your Event.observers.length is 1 > > then you want to remove test, so before you actually remove it from the > dom you are kind enough to say, > "hey, test div, stop observing that click and go have a beer" > > Event.stopObserving(''test'', ''click'', function(){ alert(''I am so happy'') > }) > > You would think that observer would have beer and get out of the > Event.observers array so length would equal Zero.The observers array is not the problem. You want the browser to stop executing the function on click, and stopObserving does work this way. The problem with your code is, that you say "react to click by executing anonymous function1" and then say "do not longer react to click by executing anonymous function2". Your functions look the same, but they are not the same objects. So the browser can''t remove the event listener. Try this in firebug: (function(){ foo }) === (function(){ foo }) The result is "false". You need to save the function on observe and pass it on stopObserving. var mycallback = function(){ alert(''I am so happy'') }; // function(ev){ alert(''I am so happy'') }.bindAsEventListener(); to get the event object Event.observe(''test'', ''click'', mycallback); Event.stopObserving(''test'', ''click'', mycallback); It will not remove the entry from the observers array, but it will remove the event listener, and this is what counts. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
heidmotron
2006-Dec-14 20:52 UTC
Re: Should Event.stopObserving() remove itself from cache?
maybe using the anonymous function was a bad example. my point is just the Event.observers array. it can get quite big if you have a ton of observers. let say you have a hundred elements each in a partial and each element has an observer for mouseover, mouseout and click a total of 300 observers if i re-render that partial instead of three hundred, I now have 600 because it doesn''t clear the old elements from the array. and if the user lets say re-renders the partial 20 times I now have 6000 objects in array. not to say that there is a performance issue because the events attach, detach regardless if there in the array or not. I''m just saying it should do a little house keeping on the array. :) cause I''m righting some test I would like to call some function assert it has added 2 observers to the array call remove and assert it has 0 observers in the array or maybe I''m too specific with my event listener. On Dec 14, 1:16 pm, "Martin Bialasinski" <klingel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12/14/06, heidmotron <matthew.heidem...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > script is: > > Event.observe(''test'', ''click'', function(){ alert(''I am so happy'') }) > > > Your Event.observers.length is 1 > > > then you want to remove test, so before you actually remove it from the > > dom you are kind enough to say, > > "hey, test div, stop observing that click and go have a beer" > > > Event.stopObserving(''test'', ''click'', function(){ alert(''I am so happy'') > > }) > > > You would think that observer would have beer and get out of the > > Event.observers array so length would equal Zero.The observers array is not the problem. You want the browser to stop > executing the function on click, and stopObserving does work this way. > The problem with your code is, that you say "react to click by > executing anonymous function1" and then say "do not longer react to > click by executing anonymous function2". Your functions look the same, > but they are not the same objects. So the browser can''t remove the > event listener. > > Try this in firebug: > (function(){ foo }) === (function(){ foo }) > > The result is "false". > > You need to save the function on observe and pass it on stopObserving. > > var mycallback = function(){ alert(''I am so happy'') }; > // function(ev){ alert(''I am so happy'') }.bindAsEventListener(); to > get the event object > > Event.observe(''test'', ''click'', mycallback); > Event.stopObserving(''test'', ''click'', mycallback); > > It will not remove the entry from the observers array, but it will > remove the event listener, and this is what counts.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
heidmotron
2006-Dec-14 21:43 UTC
Re: Should Event.stopObserving() remove itself from cache?
martin: excellent catch! I didn''t even notice that the code would still fire even because i was passing an anonymous function through stop observing. A little arrogance and stupidity on my part, I was like ''whatever I use bind method for most of my method calls'' Duh it returns anonymous function. still doesn''t answer the question about the array size. But once again thanks for an excellent catch --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Eric Harrison
2006-Dec-15 11:46 UTC
Re: Should Event.stopObserving() remove itself from cache?
I didn''t realize that your question was centered around the fact that your events were still being observed. I just thought you wanted to know what the deal was with the observers array. As stated above, you cannot remove events that you attached with an anonymous function. References: http://joseph.randomnetworks.com/archives/2006/08/01/javascript-events-with-prototype/ http://www.andrewdupont.net/2006/05/07/undecidability-of-equivalence-or-the-pitfalls-of-advanced-event-listening/ With that in mind, when you stopObserving the event, it STILL will not be removed from Event.observers for all the reasons I described in my initial email to you. Event.observers merely exists to store all of the initially observed events for IE memory leak correction. Events are added to Event.observers when you call Event.observe(), but they play no role in determining event management. Event.observers is cleared on unload if you''re using IE. That is all it does. Pretty much completely disregard Event.observers as it will never (unless you''re doing some REALLY next-level stuff) play any role in your development. But yeah, stay away from anonymous functions if there is any chance you''ll ever want to remove that event observation. -E On 12/14/06, heidmotron <matthew.heidemann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > martin: excellent catch! > I didn''t even notice that the code would still fire even because i was > passing an anonymous function through stop observing. > A little arrogance and stupidity on my part, I was like ''whatever I use > bind method for most of my method calls'' > Duh it returns anonymous function. > > still doesn''t answer the question about the array size. > > But once again thanks for an excellent catch > > > > >-- Eric Ryan Harrison --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi all, I''ll try to keep it short. I have a simple window.open(); popup. Inside I have a hidden comment div and a link: <a href="javascript:;" onclick="Effect.toggle(''comment-dialog'', ''appear'');">add new comment</a> <div id="comment-dialog" style="display:none;">....</div> But there seems to be a problem which I can''t locate. Scenario: I open the window from the parent. Click the ''add new comment'' link. The following error occurs: this.loop.bind is not a function :: error on line 238 in line effects.js - snip from effects.js - if(!this.interval) this.interval = setInterval(this.loop.bind(this), 40); - end snip . - debug info shows - this -> loop -> (prototype : Object) - end debug - And nothing else insise the loop Obj. When I reload the popup (F5) and click the same link, the link then works? - debug info shows - this -> loop -> (prototype : Object), (), (bind), (bindAsEventListener) - end debug - Somehow the bind and bindAsEvent.. got added to the stack? Hopefully someone can explain this to me and maybe help me out. Thanks /D --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Forgive me if this is not the case with your code, but does the window that you''re opening with window.open() have all of the javascript libraries sourced in with script tags? Each new window has a fresh window object created for it (unless otherwise hacked). If your opening window has Scriptaculous loaded but the new window is lightweight and doesn''t have it sourced in inside that window''s head, then it won''t be available to that window. Now, this is all speculation as I have no idea what your code actually has... Hope this helps... -E On 12/15/06, Danijel K. <dani-oEs7BEOzz4leoWH0uzbU5w@public.gmane.org> wrote:> > Hi all, > > I''ll try to keep it short. > > I have a simple window.open(); popup. Inside I have a hidden comment div > and a link: > > <a href="javascript:;" onclick="Effect.toggle(''comment-dialog'', > ''appear'');">add new comment</a> > <div id="comment-dialog" style="display:none;">....</div> > > > But there seems to be a problem which I can''t locate. > > > Scenario: I open the window from the parent. Click the ''add new comment'' > link. The following error occurs: > this.loop.bind is not a function :: error on line 238 in line effects.js > > - snip from effects.js - > if(!this.interval) > this.interval = setInterval(this.loop.bind(this), 40); > - end snip . > > - debug info shows - > this -> loop -> (prototype : Object) > - end debug - > > > And nothing else insise the loop Obj. When I reload the popup (F5) and > click the same link, the link then works? > > - debug info shows - > this -> loop -> (prototype : Object), (), (bind), (bindAsEventListener) > - end debug - > > > Somehow the bind and bindAsEvent.. got added to the stack? > Hopefully someone can explain this to me and maybe help me out. > > Thanks > /D > > > > >-- Eric Ryan Harrison --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Eric Harrison wrote:> I didn''t realize that your question was centered around the fact that > your events were still being observed. I just thought you wanted to > know what the deal was with the observers array. > > As stated above, you cannot remove events that you attached with an > anonymous function.It was''t stated above, and you can: element.onclick = null; will remove all the onclick handlers from element.> References: > > http://joseph.randomnetworks.com/archives/2006/08/01/javascript-events-with-prototype/Which states: "You can not use Event.stopObserving if you used an anonymous function in Event.observe." Which isn''t quite right - you can use it but it won''t work. What it should say is that Event.stopObserving can''t remove anonymous functions. And if you know that, and that you *can* remove anonymous functions from an element provided you don''t mind removing all of them, then you might be able to design around the issue. It is also good to know that Event.stopObserving() is only useful if you have attached multiple handlers for the same event, or only want to remove a particular named function.> http://www.andrewdupont.net/2006/05/07/undecidability-of-equivalence-or-the-pitfalls-of-advanced-event-listening/ >The myth is perpetuated: "if we try to assign the [anonymous] event listener in this manner, we won''t be able to remove it later" Which is plain wrong, see above. -- Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Michaux
2006-Dec-16 08:05 UTC
Re: Should Event.stopObserving() remove itself from cache?
On 12/15/06, Eric Harrison <blister-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > But yeah, stay away from anonymous functions if there is any chance > you''ll ever want to remove that event observation.In the spirit of this comment it isn''t it more than just anonymous function that are the problem? <pseudocode> function attachMyObserver() { function handler(){} attach("myDiv", ''click'', handler); } </pseudocode> So it isn''t an anonymous function but a named inner function. Now how would i detach just that handler? There isn''t a reference to it outside the outer function. Peter ------- http://forkjavascirpt.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Michaux
2006-Dec-16 08:11 UTC
Re: Should Event.stopObserving() remove itself from cache?
On 12/14/06, heidmotron <matthew.heidemann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > maybe using the anonymous function was a bad example. > > my point is just the Event.observers array. it can get quite big if you > have a ton of observers. > let say you have a hundred elements each in a partial and each element > has an observer for mouseover, mouseout and click > a total of 300 observers > > if i re-render that partial > instead of three hundred, I now have 600 because it doesn''t clear the > old elements from the array. > and if the user lets say re-renders the partial 20 times I now have > 6000 objects in array.Yes it probably should for safe measure as pages live longer and longer all the time. I borrowed the Yahoo! UI YAHOO.util.Event.purgeElement() function and blended it with the Prototype DOM manipulation functions to update, replace, remove some HTML. Have a look at the remove function at the bottom of this page... <URL: http://dev.forkjavascript.org/trac/browser/trunk/public/javascripts/fork/mutate.js> and the purgeElement function here <URL: http://dev.forkjavascript.org/trac/browser/trunk/public/javascripts/fork/event.js> Peter ------- http://forkjavascript.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Michaux wrote:> On 12/15/06, Eric Harrison <blister-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > But yeah, stay away from anonymous functions if there is any chance > > you''ll ever want to remove that event observation. > > In the spirit of this comment it isn''t it more than just anonymous > function that are the problem?No.> > <pseudocode> > > function attachMyObserver() { > function handler(){} > attach("myDiv", ''click'', handler); > } > > </pseudocode> > > So it isn''t an anonymous function but a named inner function. Now how > would i detach just that handler? There isn''t a reference to it > outside the outer function.The reference is ''handler'', you pass it in the call, it creates a closure back to the outer function. -- Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Michaux
2006-Dec-16 13:27 UTC
Re: Should Event.stopObserving() remove itself from cache?
On 12/16/06, RobG <rgqld-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> > <pseudocode> > > > > function attachMyObserver() { > > function handler(){} > > attach("myDiv", ''click'', handler); > > } > > > > </pseudocode> > > > > So it isn''t an anonymous function but a named inner function. Now how > > would i detach just that handler? There isn''t a reference to it > > outside the outer function. > > The reference is ''handler'', you pass it in the call, it creates a > closure back to the outer function.So what is the syntax to do this? <pseudocode> function attachMyObserver() { function handler(){} attach("myDiv", ''click'', handler); } attachMyObserver(); detach(''myDiv'', ''click'', handler); </pseudocode> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Michaux wrote:> On 12/16/06, RobG <rgqld-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote: > > > > <pseudocode> > > > > > > function attachMyObserver() { > > > function handler(){} > > > attach("myDiv", ''click'', handler); > > > } > > > > > > </pseudocode> > > > > > > So it isn''t an anonymous function but a named inner function. Now how > > > would i detach just that handler? There isn''t a reference to it > > > outside the outer function. > > > > The reference is ''handler'', you pass it in the call, it creates a > > closure back to the outer function. > > So what is the syntax to do this? > > <pseudocode> > > function attachMyObserver() { > function handler(){} > attach("myDiv", ''click'', handler); > } > > attachMyObserver(); > detach(''myDiv'', ''click'', handler); > > </pseudocode>var fn = (function(){ function handler(){...} return { addHandler : function(el, eType){ attach(el, eType, handler); }, delHandler : function(el, eType){ detach(el, eType, handler); } }; })(); fn.addHandler(...); fn.delHandler(...); QED :-) There are other (probably less efficient) methods but the principle is the same. -- Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Michaux
2006-Dec-16 14:08 UTC
Re: Should Event.stopObserving() remove itself from cache?
On 12/16/06, RobG <rgqld-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> > Peter Michaux wrote:> > So what is the syntax to do this? > > > > <pseudocode> > > > > function attachMyObserver() { > > function handler(){} > > attach("myDiv", ''click'', handler); > > } > > > > attachMyObserver(); > > detach(''myDiv'', ''click'', handler); > > > > </pseudocode> > > > var fn = (function(){ > function handler(){...} > return { > addHandler : function(el, eType){ > attach(el, eType, handler); > }, > delHandler : function(el, eType){ > detach(el, eType, handler); > } > }; > })(); > > fn.addHandler(...); > fn.delHandler(...); >Ok. If you want to cheat ;-) I was just trying to point out that anonymous functions were not the only sticky situation and that named inner functions require more care which you showed. Peter --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey, Yes the js files in the header are normally linked on all the pages with script src... Not communicating with the window opener at all. I''ve set it up at http://www.kafic.net/pop/test.html for a better overview of the problem. I can also confirm that this does work in ie7 but not the latest firefox? Eric Harrison wrote:> Forgive me if this is not the case with your code, but does the window > that you''re opening with window.open() have all of the javascript > libraries sourced in with script tags? Each new window has a fresh > window object created for it (unless otherwise hacked). If your > opening window has Scriptaculous loaded but the new window is > lightweight and doesn''t have it sourced in inside that window''s head, > then it won''t be available to that window. > > Now, this is all speculation as I have no idea what your code actually has... > > Hope this helps... > > -E > > On 12/15/06, Danijel K. <dani-oEs7BEOzz4leoWH0uzbU5w@public.gmane.org> wrote: > >> Hi all, >> >> I''ll try to keep it short. >> >> I have a simple window.open(); popup. Inside I have a hidden comment div >> and a link: >> >> <a href="javascript:;" onclick="Effect.toggle(''comment-dialog'', >> ''appear'');">add new comment</a> >> <div id="comment-dialog" style="display:none;">....</div> >> >> >> But there seems to be a problem which I can''t locate. >> >> >> Scenario: I open the window from the parent. Click the ''add new comment'' >> link. The following error occurs: >> this.loop.bind is not a function :: error on line 238 in line effects.js >> >> - snip from effects.js - >> if(!this.interval) >> this.interval = setInterval(this.loop.bind(this), 40); >> - end snip . >> >> - debug info shows - >> this -> loop -> (prototype : Object) >> - end debug - >> >> >> And nothing else insise the loop Obj. When I reload the popup (F5) and >> click the same link, the link then works? >> >> - debug info shows - >> this -> loop -> (prototype : Object), (), (bind), (bindAsEventListener) >> - end debug - >> >> >> Somehow the bind and bindAsEvent.. got added to the stack? >> Hopefully someone can explain this to me and maybe help me out. >> >> Thanks >> /D >> >> >> > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
There was a threat (or even a bug on Trac) about a bug in Firefox 2 relating to window.open(). I think this is what you see. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---