11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

To capture more than one event, you should bitwise OR ( | ) the desired event masks together.<br />

For example, to capture all click, dblClick, and blur events you might use<br />

document.captureEvents(Event.CLICK | Event.DBLCLICK | Event.BLUR);<br />

Turning off event capture is carried out analogously. You invoke the releaseEvents() method of<br />

the appropriate object, passing the bitmask of the events to release as the argument. To turn<br />

off event capturing of blur and click events at the Document level, you use<br />

document.releaseEvents(Event.BLUR | Event.CLICK);<br />

Event Propagation and Routing<br />

Because Netscape propagates events top-down, handlers at a higher level in the document‘s<br />

object tree always have the opportunity to handle an event before those at a lower level. If you<br />

have instructed the Window and the Document to capture click events, for example, the<br />

Window will capture the event because it is higher up the document object hierarchy.<br />

Sometimes, however, a handler at a higher level might wish to not handle a particular event.<br />

For example, you might be capturing all clicks at the Document level in order to handle all<br />

button clicks in a single place. But the handler might receive a click event that wasn‘t on a<br />

button, and therefore you may wish the event to continue on its journey to its intended target (a<br />

link, for example).<br />

To let an event proceed along down the hierarchy, a handler invokes the routeEvent() method<br />

with the event it is processing as the argument. As an example, consider that you might want to<br />

process clicks in a special manner if the user has the ALT key depressed.<br />

You might capture clicks at the Window level, examine the Event, and pass it along to be<br />

handled by lower-level handlers if the ALT key isn‘t depressed.<br />

function handleClicks(event)<br />

{<br />

}<br />

if (event.modifiers & Event.ALT_MASK)<br />

{<br />

}<br />

else<br />

// do something special because they have ALT depressed<br />

routeEvent(event);<br />

window.captureEvents(Event.CLICK);<br />

window.onclick = handleClicks;<br />

An occasionally useful aspect of routeEvent() is that it returns the value that the handler<br />

eventually processing the object returns. Because of this, handlers higher up the hierarchy can

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!