dhtml.lib.js - AJAX Code Search ~ Ajax Training, Learn Ajax Video Tutorials Online, Ajax Examples
Ajax Training, Learn Ajax Video Tutorials Online, Ajax Examples: dhtml.lib.js - AJAX Code Search

dhtml.lib.js - AJAX Code Search

// Copyright (c) 2006 J. Woodo (http://www.phpcow.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// VERSION 0.1

/**
* @fileoverview Cross browser implementation of various DHTML methods
* @author J. Woodo phpcow at gmail.com
* @version 0.1
*/

var Dhtml = {
isOpera: navigator.userAgent.toLowerCase().indexOf('opera') > -1,
getStyle: function(obj, styleName) {
var style = null;
var t = obj.offsetTop;
if (obj.style[styleName]) {
} else if (obj.currentStyle) {
style = obj.currentStyle[styleName];
} else if (window.getComputedStyle) {
style = document.defaultView.getComputedStyle(obj,null).getPropertyValue(styleName);
}
return style;
},
getObjectTop: function (obj) {
var top = 0;
while(obj) {
if (obj.offsetTop) {
if (!this.isOpera) {
var borderWidth = parseInt(this.getStyle(obj.offsetParent, 'borderTopWidth')) || parseInt(this.getStyle(obj.offsetParent, 'border-top-width'));
if (!isNaN(borderWidth)) {
top += borderWidth;
}
}
if (obj.scrollTop && obj.scrollTop > 0) {
top -= obj.scrollTop;
}
top += obj.offsetTop;
} else if (obj.x) {
top += obj.x;
}
obj = obj.offsetParent;
}
return top;
}, getObjectLeft: function (obj) {
var left = 0;
while (obj) {
if (obj.offsetLeft) {
if (!this.isOpera) {
var borderWidth = parseInt(this.getStyle(obj.offsetParent, 'borderLeftWidth')) || parseInt(this.getStyle(obj.offsetParent, 'border-left-width'));
if (!isNaN(borderWidth)) {
left += borderWidth;
}
}
left += obj.offsetLeft;
} else if (obj.y) {
left += obj.y;
}
obj = obj.offsetParent;
}
return left;
}, getObjectWidth: function (obj) {
var width = 0;
if (obj) {
if (obj.offsetWidth) {
width = obj.offsetWidth;
} else if (obj.clip && obj.clip.width) {
width = obj.clip.width;
} else if (obj.style && obj.style.pixelWidth) {
width = obj.style.pixelWidth;
}
}
return parseInt(width);
}, getObjectHeight: function (obj) {
var height = 0;
if (obj) {
if (obj.offsetHeight) {
height = obj.offsetHeight;
} else if (obj.clip && obj.clip.Height) {
height = obj.clip.Height;
} else if (obj.style && obj.style.pixelHeight) {
height = obj.style.pixelHeight;
}
}
return parseInt(height);
}, getObjectXY: function (obj) {
return {x: this.getObjectLeft(obj), y: this.getObjectTop(obj)};
}, getMouseXY: function(e) {
var mouseX, mouseY;
if (window.event) {
e = window.event;
mouseX = e.clientX;
mouseY = e.clientY;
if(document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
mouseX += document.documentElement.scrollLeft;
mouseY += document.documentElement.scrollTop;
} else if(document.body && (document.body.scrollTop || document.body.scrollLeft)) {
mouseX += document.body.scrollLeft;
mouseY += document.body.scrollTop;
}
} else if(e) {
if(typeof(e.pageX) == 'number') {
mouseX = e.pageX;
mouseY = e.pageY;
} else {
mouseX = e.clientX;
mouseY = e.clientY;
}
}
return {x: mouseX, y: mouseY};
}, getParent: function(obj, parentTagName) {
var parentNode = obj.parentNode;
while(parentNode) {
if (parentNode.tagName == parentTagName.toUpperCase()) {
return parentNode;
}
parentNode = parentNode.parentNode;
}
}
}

Related Posts by Categories

0 comments:

Useful Links on Adobe Flex

Your Ad Here

Latest Books on Adobe Flex