Main Page

oEvent

}
return oEvent;
};
The
preventDefault()
method is next. Just define a method for the
event
object that sets its
returnValue
to
false
:
EventUtil.formatEvent = function (oEvent) {
if (isIE && isWin) {
oEvent.charCode = (oEvent.type == “keypress”) ? oEvent.keyCode : 0;
oEvent.eventPhase = 2;
oEvent.isChar = (oEvent.charCode > 0);
oEvent.pageX = oEvent.clientX + document.body.scrollLeft;
oEvent.pageY = oEvent.clientY + document.body.scrollTop;
oEvent.preventDefault = function () {
this.returnvalue = false;
};
}
return oEvent;
};
Note the use of the
this
object. In the context of an
event
object method,
this
refers to the
event
object.
The
relatedTarget
property can be either the
fromElement
or
toElement
property depending on the
event type:
EventUtil.formatEvent = function (oEvent) {
if (isIE && isWin) {
oEvent.charCode = (oEvent.type == “keypress”) ? oEvent.keyCode : 0;
oEvent.eventPhase = 2;
oEvent.isChar = (oEvent.charCode > 0);
oEvent.pageX = oEvent.clientX + document.body.scrollLeft;
oEvent.pageY = oEvent.clientY + document.body.scrollTop;
oEvent.preventDefault = function () {
this.returnValue = false;
};
if (oEvent.type == “mouseout”) {
oEvent.relatedTarget = oEvent.toElement;
} else if (oEvent.type == “mouseover”) {
oEvent.relatedTarget = oEvent.fromElement;
}
}
return oEvent;
};
The
screenX
,
screenY
, and
shiftKey
properties are all the same, so no work there. That brings up the
stopPropagation()
method, which simply involves setting
cancelBubble
to
true
:
EventUtil.formatEvent = function (oEvent) {
if (isIE && isWin) {
oEvent.charCode = (oEvent.type == “keypress”) ? oEvent.keyCode : 0;
oEvent.eventPhase = 2;
297
All about Events
12_579088 ch09.qxd 3/28/05 11:39 AM Page 297


JavaScript EditorFree JavaScript Editor     Ajax Editor


©