P
Peter Michaux
Older? IIRC, they were both introduced in JS 1.3.
and JScript 5.5 according to Thomas Lahn's page
<URL:http://pointedears.de/scripts/es-matrix/>
I really thought there was one browser I encountered where it had
apply and not call. Anyway apply is what I need in this case.
[snip]
LIB.addListener = function(element, eventType,
handler, options) {
var listener = createListener(element, eventType,
handler, options);
element.addEventListener(
listener.eventType,
listener.wrappedHandler,
false);
listeners[listeners.length] = listener;
Make sure that the listeners array does not end up sharing a closure
with this code (as it does here.) I assume that unload cleanup logic
will follow at some point, but AIUI, such code doesn't do a bit of
good for elements that have been removed from their documents (e.g. by
innerHTML replacement.) IIRC, you covered this in your FORK library.I don't really follow and these circular references make my head hurt.
If your array that holds references to the elements with attached
listeners shares a closure with the wrapped listener functions, you
will create a new circular reference every time.
But for IE onunload I'm using detachEvent so the element no longer has
a reference to the functions involved. That should take care of it.
Yes, but apply this to the IE branch,
I use detachEvent on all the listeners in the IE branch.
which also stores element
references (two references each as I recall, one to keep track of the
listeners per element and one for cleanup.)
As long as detachEvent is used, the problem should be solved
regardless of the number of places I have references to the the
handlers and wrapped handlers and if those have the element in the
closure. Just one break in the circle is enough, I thought.
[snip]
But aren't they just mapped to the window unload event? An onload
attribute on the body can be overwritten by assigning something to
window.onload. Is this not the same for unload?
I don't know.
[snip]
I don't think it is a good idea for listeners to remove themselves
during an event.
That is what happens at the end of a drag operation. When the mouseup
event occur both the mousemove and mouseup listeners are removed. At
least that is one way to do it.
[snip]
I would be careful about assuming anything about the window object.
Can it really be expected to receive click events in all (or even
most) implementations?
Before using the Safari workaround I check that
typeof global.onclick == 'object'
before anything has been assigned to global.onclick. When a function
is assigned the typeof value is 'function'. That is true in at least
safari so it is a safe bet that the event will bubble up to the
window.
I would avoid using LIB.* or API.* or whatever in the internal code.
Doing so also makes the code less portable.
Portable to where?
Peter