R
Ralph
Hi
I have a problem understanding why events are triggered in the way they are in the example below.
I have a function assigning events to DOM objects:
addEventHandler = function (oTarget, sEventType, fnHandler) {
if (oTarget.addEventListener) {
oTarget.addEventListener(sEventType, fnHandler, false);
} else if (oTarget.attachEvent) {
oTarget.attachEvent("on" + sEventType, fnHandler);
} else {
oTarget["on" + sEventType] = fnHandler;
}
};
Using this function I'm attaching event handling functions like this:
var el = document.getElementById('contDiv');
addEventHandler(el, 'drag', test);
addEventHandler(el, 'mouseup', test);
addEventHandler(el, 'mousedown', test);
addEventHandler(el, 'mousedown', test);
addEventHandler(el, 'mouseover', test);
Where test function is to display types of events in textarea:
function() {
var e = EventUI.getEvent();
var test = document.getElementById('teste');
test.innerHTML += e.type + "\n";
return false;
}
OK now to the point:
When I drag across my div in IE I get following events:
mouseover - mousedown - mousedown - drag - mouseover - mouseup
And thats what I'm expecting it to do (I removed a lot mouseover events to keep it clear).
BTW: The cursor is still an arrow when I'm dragging across div.
In FF on the other hand I get only:
mouseover - mousedown - mouseover
So I'dont get second on mousedown and I don't get onmouseup. While dragging my cursor takes shape of
cross out circle.
I found the solution to it by attaching the events in this manner:
var el = document.getElementById('contDiv');
addEventHandler(el, 'drag', test);
addEventHandler(el, 'mouseup', test);
document.getElementById('contDiv').onmousedown=test;
addEventHandler(el, 'mousedown', test);
addEventHandler(el, 'mouseover', test);
Now it works in FF and IE.
FF:
mouseover - mousedown - mousedown - mouseover - mouseup
IE:
mouseover - mousedown - mousedown - drag - mouseover - mouseup
WHY ?
If anyone knows why its like this please respond.
Thank you very much.
I have a problem understanding why events are triggered in the way they are in the example below.
I have a function assigning events to DOM objects:
addEventHandler = function (oTarget, sEventType, fnHandler) {
if (oTarget.addEventListener) {
oTarget.addEventListener(sEventType, fnHandler, false);
} else if (oTarget.attachEvent) {
oTarget.attachEvent("on" + sEventType, fnHandler);
} else {
oTarget["on" + sEventType] = fnHandler;
}
};
Using this function I'm attaching event handling functions like this:
var el = document.getElementById('contDiv');
addEventHandler(el, 'drag', test);
addEventHandler(el, 'mouseup', test);
addEventHandler(el, 'mousedown', test);
addEventHandler(el, 'mousedown', test);
addEventHandler(el, 'mouseover', test);
Where test function is to display types of events in textarea:
function() {
var e = EventUI.getEvent();
var test = document.getElementById('teste');
test.innerHTML += e.type + "\n";
return false;
}
OK now to the point:
When I drag across my div in IE I get following events:
mouseover - mousedown - mousedown - drag - mouseover - mouseup
And thats what I'm expecting it to do (I removed a lot mouseover events to keep it clear).
BTW: The cursor is still an arrow when I'm dragging across div.
In FF on the other hand I get only:
mouseover - mousedown - mouseover
So I'dont get second on mousedown and I don't get onmouseup. While dragging my cursor takes shape of
cross out circle.
I found the solution to it by attaching the events in this manner:
var el = document.getElementById('contDiv');
addEventHandler(el, 'drag', test);
addEventHandler(el, 'mouseup', test);
document.getElementById('contDiv').onmousedown=test;
addEventHandler(el, 'mousedown', test);
addEventHandler(el, 'mouseover', test);
Now it works in FF and IE.
FF:
mouseover - mousedown - mousedown - mouseover - mouseup
IE:
mouseover - mousedown - mousedown - drag - mouseover - mouseup
WHY ?
If anyone knows why its like this please respond.
Thank you very much.