13.02.2013 Views

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

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.

236<br />

document.getElementsByTagName("body")[0].appendChild(ghostMarker);<br />

}<br />

ghostMarker.marked = closest.element;<br />

ghostMarker.style.left = closest.offsetX + "px";<br />

ghostMarker.style.top = closest.offsetY + "px";<br />

}<br />

else<br />

{<br />

var ghostMarker = document.getElementById("ghostMarker");<br />

}<br />

if (ghostMarker != null)<br />

{<br />

ghostMarker.parentNode.removeChild(ghostMarker);<br />

}<br />

event.returnValue = false;<br />

if (typeof event.preventDefault != "undefined")<br />

{<br />

event.preventDefault();<br />

}<br />

return true;<br />

};<br />

The first order of business for this function is to change the position of the ghost so that it looks like it’s following the user’s<br />

mouse cursor. We do this by calculating how far the user has moved from the original mousedown point, and then setting<br />

the margins on the ghost div to reflect this difference. The current coordinates of the mouse cursor are again obtained<br />

using event.clientX and event.clientY, and the global dragOrigin variable is used for the original mousedown<br />

coordinates.<br />

mousedownDocument() then needs to use our map of the other modules to figure out the new insertion point of the dragged<br />

module. We know the location of the ghost div, and we know the location of each of the static modules’ top-left corners,<br />

so it’s quite easy to figure out which static module the ghost is nearest. We want to insert the dragged module before that<br />

static module.<br />

For each entry in dragHotspots, we do a quick test of the horizontal position of the ghost. If no part of the ghost is within<br />

the width of the module area where the static module is located, we don’t want to consider it as a viable destination for the<br />

dragged module. So we check whether the right edge of the ghost is right of the static module’s left edge and whether the left<br />

edge of the ghost is left of the static module’s right edge. This means that some part of the ghost is overlapping the width of<br />

the module area.

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

Saved successfully!

Ooh no, something went wrong!