result = (o[sHandler] == fListener);
-result- will always be false, but logically it must be true.
Thanks. You are correct; that was a relic from the previous version. Fixed
with
var oldListener = o["on" + sEvent];
var newListener = function(e)
{
if (!e)
{
e = (typeof _global.window != "undefined"
&& typeof window.event != "undefined"
&& window.event);
}
If either of the first two tests fail, e will go from undefined to
false. Also, you first check if window is a property of the Global
Object, then turn right around and refer to the same identifier
implicitly.
This would seem sufficient:
e = e || window.event;
Or if you want to be more explicit:
if (!e && _global.window) {
e = _global.window.event;
}
It is hard to imagine an implementation that would throw an exception
on [[Get]] for the window object. Methods of this (or any host
object) are another story (as we have been over recently.)
Or if you must:
if (!e && typeof _global.window == 'object' && _global.window) {
e = _global.window.event;
}
Or to be really paranoid about host object implementations:
if (!e && typeof _global.window != 'undefined') {
e = _global.window.event;
}
But show me one agent that returns anything other than "object" for
typeof window. If there is one that screwy, who is to say that it
wouldn't return a null value for window or throw a [[Get]] exception
on window.event? The fact that such an agent could exist in the
future is a good argument for encapsulating such tests in a central
function (as we have also been over recently.) Regardless, there is
no surefire way to know if a host object will throw an exception on
evaluation.
Either way, assuming no [[Get]] exceptions, e will be an event object
or undefined (but never false.) Personally, I would use the first
one, possibly checking for the existence of the window object prior to
creating the function (or assigning the global event property as
window and the Global Object share the same scope.) The second option
would be:
e = e || _global.event;
Unless you think that IE8 or newer will give window a different scope
than the Global object (obviously won't happen), then this is
sufficient. Here's hoping that IE8 does away with the ridiculous
global event object altogether.
This snippet appears to be part of a general solution, which should
take into account that elements passed may not reside in the same
frame. Also, expandos are always a bad idea. If you must use them,
you need to check the document.expando property first.
Looking at the file it came from, I see a few other problems.
if (typeof oScript.type != "undefined")
{
oScript.type = sType || "text/javascript";
}
if (typeof oScript.type != "undefined")
{
oScript.type = sType || "text/javascript";
}
That is clearly a copy and paste error.
if (isMethod(typeof aHeads[0].appendChild))
I assume this is a typo and isMethodType was meant.
// makes the method applicable to Document and Element objects
if (!o
&& typeof this.constructor != "undefined"
&& /Document|Element/.test(String(this.constructor)))
{
o = this;
}
You wouldn't augment host objects would you? Regardless, this is pure
evil.
Next line:
if (o && isMethod(typeof o.getElementsByTagName))
Same typo as before I assume.
if (typeof HTMLDocument != "undefined"
&& typeof HTMLDocument.prototype != "undefined")
{
HTMLDocument.prototype.getElementsByTabIndex =
getElementsByTabIndex;
}
if (typeof HTMLElement != "undefined"
&& typeof HTMLElement.prototype != "undefined")
{
HTMLElement.prototype.getElementsByTabIndex = getElementsByTabIndex;
}
OMG. No you didn't.
Your attribute alias map lists rowspan, but not colspan. Both get and
set attribute functions have problems. See the version proposed in
the CWR project. It needs to be revised as I recently fixed a couple
of problems, but it should indicate areas that you need to improve in
your code.
The get and set style property functions don't handle float properly.
The show function is roughly equivalent to Prototype's, which is to
say worthless.
The getParent function is ambiguous as parentNode and parentElement
are not equivalent.
The getAbsPos function is severely lacking. For one it completely
ignores borders.
This looks wrong:
if (typeof _global != "undefined")
{
var _global = this;
}
Perhaps you meant:
if (typeof _global == "undefined")
The test isn't needed anyway.
var dhtml = new DHTML();
Shouldn't this library be a singleton?
Overall, feature testing should be pulled out of the functions and the
repetitive comments should be trimmed. You should run it through
JSLint as minification is to be expected (nobody wants to download all
of those credits.)