P
Paul Cooper
Dear All,
I am working on a piece of Javascript code that needs to detect a
mouse-click, shift-click and control-click. The code is not my own -
it is a part of a much larger suite of routines. The code as it stands
does not work in Firefox, and I suspect that the task of feature
detection (which currently depends on browser detection) can be
carried out better. The result should be that opcode is set to 0,1 or
2 dor click, control-click and shift-click. I post the entire function
below.
Thanks
Paul
function click(e)
{
if(!e)
e=window.event;
var mX=null;
var mY=null;
var opcode = 0; //0=zoom in, 1=zoom to extent (ctrl), 2=pan
(shift)
var op=navigator.userAgent.toLowerCase().indexOf('opera')!=-1;
var ie = document.all;
if (ie || op)
{
mX = e.offsetX;
mY = e.offsetY;
if (e.ctrlKey)
opcode = 1;
if (e.shiftKey)
{
opcode += 2;
}
}
else
{
mX = e.layerX;
mY = e.layerY;
if (e.modifiers & Event.CONTROL_MASK)
{
opcode = 1;
}
if (e.modifiers & Event.SHIFT_MASK)
{
opcode += 2;
}
}
if (opcode == 0)
{
this.zoom(mX,mY);
}
else if (opcode == 1)
{
this.zoomOut(mX,mY);
}
else if (opcode == 2)
{
this.pan(mX,mY);
}
else if (opcode == 3)
{
this.queryUI(mX,mY);
}
}
I am working on a piece of Javascript code that needs to detect a
mouse-click, shift-click and control-click. The code is not my own -
it is a part of a much larger suite of routines. The code as it stands
does not work in Firefox, and I suspect that the task of feature
detection (which currently depends on browser detection) can be
carried out better. The result should be that opcode is set to 0,1 or
2 dor click, control-click and shift-click. I post the entire function
below.
Thanks
Paul
function click(e)
{
if(!e)
e=window.event;
var mX=null;
var mY=null;
var opcode = 0; //0=zoom in, 1=zoom to extent (ctrl), 2=pan
(shift)
var op=navigator.userAgent.toLowerCase().indexOf('opera')!=-1;
var ie = document.all;
if (ie || op)
{
mX = e.offsetX;
mY = e.offsetY;
if (e.ctrlKey)
opcode = 1;
if (e.shiftKey)
{
opcode += 2;
}
}
else
{
mX = e.layerX;
mY = e.layerY;
if (e.modifiers & Event.CONTROL_MASK)
{
opcode = 1;
}
if (e.modifiers & Event.SHIFT_MASK)
{
opcode += 2;
}
}
if (opcode == 0)
{
this.zoom(mX,mY);
}
else if (opcode == 1)
{
this.zoomOut(mX,mY);
}
else if (opcode == 2)
{
this.pan(mX,mY);
}
else if (opcode == 3)
{
this.queryUI(mX,mY);
}
}