Search

8/22/2007

__defineGetter__ and __defineSetter__

http://webfx.eae.net/dhtml/ieemu/eventobject.html

The problem shows up when you try to get the target when you click on a link with some text in it. IE (using srcElement) returns the link but Mozilla returns the text node (using target) inside the link.

Source Element
Event.prototype.__defineGetter__("srcElement", function () {
var node = this.target;
while (node.nodeType != 1) node = node.parentNode;
return node;
}

Cancel the event bubble
Event.prototype.__defineSetter__("cancelBubble", function (b) {
if (b) this.stopPropagation();
});

Preventing default actions
Event.prototype.__defineSetter__("returnValue", function (b) {
if (!b) this.preventDefault();
});

offsetX and offsetY
Event.prototype.__defineGetter__("offsetX", function () {
return this.layerX;
});

Event.prototype.__defineGetter__("offsetY", function () {
return this.layerY;
});

沒有留言: