D
David Mark
I am not experiencing any difficulties here yet. This is probably
because I am not writing any general widgets that can be used
anywhere. My widgets are used in my app environment where all elements
are positioned absolute. My sizing, resizing, and drag routines are
working fine, no pain yet. Or maybe you are referring to some
difficulties that I have not yet encountered.
Try adding borders to the body or html elements. To compound the
problem, add margins to the html element. Then try to compute the
position of an absolute element in just the major browsers in
standards mode. I imagine you will need the viewport rectangle at
some point as well. Have fun with that.
I started with the YUI libraries and tried to fix at least everything
that was wrong/less than optimal in my eyes.
Peter
I had a look at your code - great stuff! I had a look at your event
routines to check whether my code is up to scratch (I am new to JS). I
actually found your code "quite" similar to mine, which serves as a
confirmation to me that I am on the right track. If I would have
looked at your code previously then it would have saved me quite some
work yesterday ;-) On the other had, in my opinion it is good to have
written such stuff totally from scratch so that one fully understands
the issues
involved.
For those interested, here is my (stripped) version of a simple event
handler:
(Comments, questions and suggestions are welcome)
var TVSEvent = {
Handlers: [],
IndexOfHandler: function(aHandler) {
var hidx = -1;
for(var i = 0, length = this.Handlers.length; i < length; i++) {
var hob = this.Handlers;
if((hob.Handler == aHandler) || (hob.DOMHandler == aHandler)) {
hidx = i;
break;
}
}
return hidx;
},
Add: function(aNode, aType, aHandler, aScope) {
var domh = aHandler;
if(arguments.length >= 4) {
domh = function() {
return aHandler.apply(aScope, arguments);
}
}
this.Handlers[this.Handlers.length] = {
Handler: aHandler,
DOMHandler: domh
}
if(aNode.addEventListener) {
aNode.addEventListener(aType, domh, false);
} else if(aNode.attachEvent) {
aNode.attachEvent('on' + aType, domh);
}
return domh;
},
Remove: function(aNode, aType, aHandler) {
var domh = aHandler;
var eidx = this.IndexOfHandler(domh);
if(eidx >= 0) {
domh = this.Handlers[eidx].DOMHandler;
this.Handlers.splice(eidx, 1);
}
if(aNode.removeEventListener) {
aNode.removeEventListener(aType, domh, false);
} else if(aNode.detachEvent) {
aNode.detachEvent('on' + aType, domh);
}
}
You should feature detect once and be done with it. And if you are
going to write a wrapper for event handling, you should smooth out the
basic differences between the two models. It doesn't make sense to
normalize everything for every event (like most libs do), but at least
pass along the event object and fix "this" handling for IE.