AJAX - The Complete Reference

(avery) #1

370 Part II: Developing an Ajax Library^


padding: 10px;
border: solid 2px black; }
.draggable {cursor: move;}
.draggable:hover {border: solid 5px yellow;}

</style>
<script type="text/javascript"
src="http://ajaxref.com/ch8/ajaxtcr.js"></script>
<script type="text/javascript">
function getStyle(obj, styleName)
{ /* abstraction to address varying browser methods to calculate a style value */
var style = "";
if (obj.style[styleName])
style = obj.style[styleName];
else if (obj.currentStyle)
style = obj.currentStyle[styleName];
else if (window.getComputedStyle)
{
var computedStyle = window.getComputedStyle(obj, "");
style = computedStyle.getPropertyValue(styleName);
}
return style;
}

function getHighestZIndex()
{ /* find the highest Z-index in the document to put the drug object
higher */

var highestZIndex = 0;
var elements = document.getElementsByTagName("*");
for (var i=0;i<elements.length;i++)
{
var curZIndex = getStyle(elements[i], "zIndex");
if (curZIndex != "")
highestZIndex = Math.max(highestZIndex, parseInt(curZIndex));
}
return highestZIndex;
}

/* addressing the wonderful world of cross-browser event handling */
function fixE(e) { return e || window.event; }

function getPosition(e)
{ /* make sure to compensate for the different position
value calculations in browsers */
var position = {};
if (e.pageX)
{
position.x = e.pageX;
position.y = e.pageY;
}
Free download pdf