Alright, I'll explain what is going on -- but it is kind of wonky.
// This is a cheap duck test. normally, only a "top level" object would contain
// a setInterval property/method
// By top level, that pretty much means a window, a frame, or an iframe.
// So this is a lame/broken test for that.
if (elem.setInterval
&&
// Then we check to see if we have a window or a frame.
( elem != window && !elem.frameElement ) ) {
// If we don't have either, assume that we were passed something totally bogus
// and assign this to the window value.
elem = window;
}
Without reading the API, I did look at the code. A far, far better way to write that would be closer to:
add: function(elem, type, handler) {
if (elem === undefined) {
elem = window;
}
or, as I'd write it:
add: function(elem, type, handler) {
// MUCH better test is shown here:
// http://stackoverflow.com/questions/384286/javascript-isdom-how-do-you-check-if-a-javascript-object-is-a-dom-object
if (elem === undefined) {
throw "Event.Add warning. Must pass an element to bind the event to."
}