Event.stopObserving() doesn't work for window as only argument.

133 views
Skip to first unread message

Allen

unread,
Aug 11, 2009, 4:20:03 PM8/11/09
to Prototype: Core
When I do:
Event.observe(window, 'resize', alert); //Note: alert is the common
javascript alert function, but it will be called with no params.

Then I can do the following:
Event.stopObserving(window, 'resize', alert);

and:
Event.stopObserving(window, 'resize');

However I cannot do:
Event.stopObserving(window); //Firebug says "TypeError:
element.stopObserving is not a function"

This seems contradictory to the documentation here (
http://www.prototypejs.org/api/event/stopObserving ) which list the
three forms. It seems to me that it would make sense to extend window
like document is so that you could call observe and stopObserving on
it.
I would like to know, is there some reason that it behaves this way or
if its a bug. If it is I would happily write a patch for this. The
obvious concern would be browser interoperability, so if there are
reasons that window cannot be extended, I would also like to know what
those are.

Thanks!

Allen

kangax

unread,
Aug 12, 2009, 12:49:50 PM8/12/09
to Prototype: Core
On Aug 11, 4:20 pm, Allen <bla...@gmail.com> wrote:
> When I do:
> Event.observe(window, 'resize', alert); //Note: alert is the common
> javascript alert function, but it will be called with no params.
>
> Then I can do the following:
> Event.stopObserving(window, 'resize', alert);
>
> and:
> Event.stopObserving(window, 'resize');
>
> However I cannot do:
> Event.stopObserving(window); //Firebug says "TypeError:
> element.stopObserving is not a function"
>
> This seems contradictory to the documentation here (http://www.prototypejs.org/api/event/stopObserving) which list the
> three forms. It seems to me that it would make sense to extend window
> like document is so that you could call observe and stopObserving on
> it.
> I would like to know, is there some reason that it behaves this way or
> if its a bug. If it is I would happily write a patch for this. The
> obvious concern would be browser interoperability, so if there are
> reasons that window cannot be extended, I would also like to know what
> those are.
>
> Thanks!
>
> Allen

I can't reproduce this in FF 3.5.2 using latest version of Prototype.

--
kangax

Allen

unread,
Aug 12, 2009, 1:16:09 PM8/12/09
to Prototype: Core
This problem is in prototype 1.6.0. It seems the portion that fails
has been fixed in the newest on github.

Old snippet:
} else if (!eventName) {
Object.keys(getCacheForID(id)).each(function(eventName) {
element.stopObserving(eventName); //This caused the problem
});
return element;
}

New snippet:
} else if (!eventName) {
// If both the event name and the handler are omitted, we stop
observing
// _all_ handlers on the element.
registry.each( function(pair) {
var eventName = pair.key, responders = pair.value;

responders.each( function(r) {
Element.stopObserving(element, eventName, r.handler); //This
should fix it
});
});
return element;
}

However, I'm still curious why you don't extend window with observe()
and stopObserving()?
Reply all
Reply to author
Forward
0 new messages