C
Csaba2000
My comp.lang.javascript friends couldn't help me out on this one,
and you guys sometimes have insightful comments, so I hope you
don't mind if I run this by you:
If you click on or in a table and move the mouse, the default
action is that the "in between" text is supposed to get hilighted.
I can't seem to cancel this behaviour for NN 6.1. The code
below shows a way to do it for IE 5.5. This is not a major
issue, but I'd like to tidy up my code in this respect.
Thanks,
Csaba Gabor from New York
PS. Side notes: NN 6.1, in the code below, is nice enough to
note when there is a mouseup even when the mouse has
left the document area. IE loses track of the mouse status
once the mouse has exited the document area and won't
register the next mouseup even if the mouse returns over
the document (though it will start hilighting at this point).
On the other hand, IE does notify us that the mouse is
leaving the document area, whereas I haven't found a
way to do this with NN.
Opera doesn't like the document.on... constructs, but
when replaced with document.body.on... it will lose
track of the mouse when the mouse exits the body
area along certain paths (south, then west - no kidding).
It is also not cancelling the selection action.
PPS. I am allowing the user to resize a table by dragging
borders. That works in IE/NN. However, NN has this
behavioural artifact that I'd like to tidy up and that's the
motivation for the question.
<BODY style="border:solid 1px red">
Click anywhere on or within the table and drag.<br>
The text hilighting you normally see should not happen<br>
since the onmouseover event is being cancelled.<br>
<TABLE border onmousedown="dragMode(event)">
<TR>
<TD>foo</TD><TD>bar</TD>
<TR></TR>
<TD>baz</TD><TD>frob</TD>
</TR></TABLE>
<SCRIPT type="text/javascript">
function dragMode(evt) { // setup for dragging
var e = evt || window.event; // debugging
var myTarget = e.target || e.srcElement; // debugging
document.body.onmousemove = hilightCancel;
document.onmouseout = dragEndCheck;
document.onmouseup = function () {dragEnd("drag over: mouseup")};
window.status = "dragStart: " + myTarget.nodeName // debugging
}
function hilightCancel (evt) {
var e = evt || window.event; // debugging
var myTarget = e.target || e.srcElement; // debugging
// if (e.preventDefault) e.preventDefault(); // hasn't made a difference
window.status = "hilightCancel: " + myTarget.nodeName // debugging
return false; // should prevent hilighting
}
function dragEndCheck(evt) {
// needed cause IE forgets mouse status leaving the body/window
var e = evt || window.event;
var myTarget = e.target || e.srcElement;
var related = e.relatedTarget || e.toElement || e.fromElement;
var relatedName = (related&&related.nodeName)?related.nodeName:"none";
if (myTarget.nodeName!="BODY" || relatedName!="BODY") {return false;}
dragEnd ("drag over: " + myTarget.nodeName + " / " + relatedName)
}
function dragEnd(msg) {
document.body.onmousemove = null;
document.onmouseout = null;
document.onmouseup = null;
window.status = msg; // debugging
}
</SCRIPT>
</BODY>
and you guys sometimes have insightful comments, so I hope you
don't mind if I run this by you:
If you click on or in a table and move the mouse, the default
action is that the "in between" text is supposed to get hilighted.
I can't seem to cancel this behaviour for NN 6.1. The code
below shows a way to do it for IE 5.5. This is not a major
issue, but I'd like to tidy up my code in this respect.
Thanks,
Csaba Gabor from New York
PS. Side notes: NN 6.1, in the code below, is nice enough to
note when there is a mouseup even when the mouse has
left the document area. IE loses track of the mouse status
once the mouse has exited the document area and won't
register the next mouseup even if the mouse returns over
the document (though it will start hilighting at this point).
On the other hand, IE does notify us that the mouse is
leaving the document area, whereas I haven't found a
way to do this with NN.
Opera doesn't like the document.on... constructs, but
when replaced with document.body.on... it will lose
track of the mouse when the mouse exits the body
area along certain paths (south, then west - no kidding).
It is also not cancelling the selection action.
PPS. I am allowing the user to resize a table by dragging
borders. That works in IE/NN. However, NN has this
behavioural artifact that I'd like to tidy up and that's the
motivation for the question.
<BODY style="border:solid 1px red">
Click anywhere on or within the table and drag.<br>
The text hilighting you normally see should not happen<br>
since the onmouseover event is being cancelled.<br>
<TABLE border onmousedown="dragMode(event)">
<TR>
<TD>foo</TD><TD>bar</TD>
<TR></TR>
<TD>baz</TD><TD>frob</TD>
</TR></TABLE>
<SCRIPT type="text/javascript">
function dragMode(evt) { // setup for dragging
var e = evt || window.event; // debugging
var myTarget = e.target || e.srcElement; // debugging
document.body.onmousemove = hilightCancel;
document.onmouseout = dragEndCheck;
document.onmouseup = function () {dragEnd("drag over: mouseup")};
window.status = "dragStart: " + myTarget.nodeName // debugging
}
function hilightCancel (evt) {
var e = evt || window.event; // debugging
var myTarget = e.target || e.srcElement; // debugging
// if (e.preventDefault) e.preventDefault(); // hasn't made a difference
window.status = "hilightCancel: " + myTarget.nodeName // debugging
return false; // should prevent hilighting
}
function dragEndCheck(evt) {
// needed cause IE forgets mouse status leaving the body/window
var e = evt || window.event;
var myTarget = e.target || e.srcElement;
var related = e.relatedTarget || e.toElement || e.fromElement;
var relatedName = (related&&related.nodeName)?related.nodeName:"none";
if (myTarget.nodeName!="BODY" || relatedName!="BODY") {return false;}
dragEnd ("drag over: " + myTarget.nodeName + " / " + relatedName)
}
function dragEnd(msg) {
document.body.onmousemove = null;
document.onmouseout = null;
document.onmouseup = null;
window.status = msg; // debugging
}
</SCRIPT>
</BODY>