AJAX - The Complete Reference

(avery) #1

376 Part II: Developing an Ajax Library^


else
{
parent.appendChild(obj);
var offsetDiff = -20;
}

yOffset -= offsetDiff;
return false;
}
}
if (previous != null)
{
if (within(e, previous))
{
parent.removeChild(obj);
parent.insertBefore(obj, previous);
obj.style.top = "0px";
var offsetDiff = previous.offsetTop - obj.offsetTop;
yOffset -= offsetDiff;
return false;
}
}

return false
} /* end of dragMove */

When the dragDropStop() function is finally invoked upon mouse release, the
handlers are cancelled as before, but this time the final position of the list item is calculated.
We could use this information to make an Ajax request to the server indicating that the list
item was moved from its initial position to the current position.

function dragDropStop(e, obj)
{
e = fixE(e);
document.onmousemove = null;
document.onmouseup = null;
e.cancelBubble = true;
e.returnValue = false;
if (e.stopPropagation)
{
e.stopPropagation();
e.preventDefault();
}
obj.style.top = "0px";
var position = findPosition(document.getElementById("orderedList"), obj)
+ 1;
var url = "http://ajaxref.com/ch8/echo.php";
var payload = "message=" + AjaxTCR.data.encodeValue("<h3>Message from the
server:</h3><tt>Item #" + obj.id.substring(4) + " moved to position " +
position + ".</tt>");
sendRequest(url, payload);
}
Free download pdf