13.02.2013 Views

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

238<br />

ghostMarker.marked.appendChild(dragTarget);<br />

}<br />

else<br />

{<br />

ghostMarker.marked.parentNode.insertBefore(dragTarget, ghostMarker.marked);<br />

}<br />

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

}<br />

return true;<br />

};<br />

Most of the heavy lifting has already been done, so this function just tidies things up. First, it removes the mousemove event<br />

listener from the document, as we no longer need to know when the user is moving the mouse. After that, we remove the<br />

ghost element, as we want to stop displaying the copy.<br />

Then we decide where to place the dragged module. If ghostMarker still exists, it means that the user released the mouse<br />

button when there was a valid place to move the dragged module. Using the ghostMarker.marked property, we can see<br />

which element to insert the dragged module before. We need to check whether the marked module is actually a module, or<br />

whether it was the extra placeholder we put in for the end of the module area. If it’s an actual module (it has a class of<br />

module), we can use the insertBefore() method to move the dragged module before the marked module. If it was a module<br />

area, we use appendChild() to place the dragged module at the end of the area. Either way, we remove the ghost<br />

marker, and the dragged module now ends up in its new location, just where the user wanted! If ghostMarker no longer<br />

exists, we know that there’s nowhere for the dragged module to move to, so we can quietly finish.<br />

Figure 9-15 shows the whole process of a user dragging a module from one module area to another.<br />

a. b.<br />

Figure 9-15 (a-d). Dragging a module to another module area<br />

➤ ➤

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

Saved successfully!

Ooh no, something went wrong!