wrote:
> [...]
> To run the function I pass event to it:
> obj.onclick = runMe;
> function runMe(ev){
> ev = ev || window.event;
> var mousecoords = getMouseCoords(ev);
> }
>
> Question: how to simulate or avoid using "ev" variable in runMe() but
> get mouse coordinates anyway?
Not possible. An event listener has a built-in fixed signature.
> I simply want to run runMe() in many places and subroutines, so
> passing event seems to be a complicated task.
Even with event capturing, if you pass `event' from an event handler
attribute to runMe(), the lines
e = (e) ? e : window.event;
in getMouseCoords() and
ev = ev || window.event;
in runMe() are unnecessary.
However, you are looking for event bubbling, where you would need only one
event listener:
<head>
<!-- ... -->
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function handleClick(e)
{
if (e)
{
var mousecoords = getMouseCoords(e);
}
}
</script>
</head>
<body onclick="handleClick(e)">
<!-- ... -->
</body>
See
http://www.w3.org/TR/DOM-Level-2-Eve...-flow-bubbling
HTH
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$>