15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

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.

Chapter 1 ✦ Generic HTML Element Objects (Chapter 15)<br />

for different types of event processing. The srcElement property is used initially as<br />

a filter to decide whether the status bar will reveal further processing about the<br />

TEXTAREA element’s event details.<br />

The onMouseDown event handler in the BODY element triggers all event processing.<br />

IE events bubble up the hierarchy (and no events are cancelled in this page), so<br />

all mouseDown events eventually reach the BODY element. Then, the<br />

whereInWorld() function can compare each mouseDown event from any element<br />

against the textarea’s geography.<br />

Listing 15-24: Using the componentFromPoint() Method<br />

<br />

<br />

componentFromPoint() Method<br />

<br />

function whereInWorld(elem) {<br />

var x = event.clientX<br />

var y = event.clientY<br />

var component = document.all.myTextarea.componentFromPoint(x,y)<br />

if (window.event.srcElement == document.all.myTextarea) {<br />

if (component == “”) {<br />

status = “mouseDown event occurred inside the element”<br />

} else {<br />

status = “mouseDown occurred on the element\’s “ + component<br />

}<br />

} else {<br />

status = “mouseDown occurred “ + component + “ of the element”<br />

}<br />

}<br />

<br />

<br />

<br />

componentFromPoint() Method<br />

<br />

Tracking the mouseDown event relative to the textarea object. View results in<br />

status bar.<br />

<br />

<br />

This is Line 1<br />

This is Line 2<br />

This is Line 3<br />

This is Line 4<br />

This is Line 5<br />

This is Line 6<br />

<br />

<br />

<br />

<br />

63<br />

elementObject.componentFromPoint()

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

Saved successfully!

Ooh no, something went wrong!