Dwt.js
Summary
No overview generated for 'Dwt.js'
function Dwt() {
}
Dwt.STATIC_STYLE = "static";
Dwt.ABSOLUTE_STYLE = "absolute";
Dwt.RELATIVE_STYLE = "relative";
Dwt.NO_REPEAT = "no-repeat";
Dwt.REPEAT = "repeat";
Dwt.REPEAT_X = "repeat-x";
Dwt.REPEAT_Y = "repeat-y";
Dwt.DISPLAY_INLINE = "inline";
Dwt.DISPLAY_BLOCK = "block";
Dwt.DISPLAY_NONE = "none";
Dwt.LEFT = 100;
Dwt.RIGHT = 101;
Dwt.TOP = 102;
Dwt.BOTTOM = 103;
Dwt.ABOVE = 104;
Dwt.BELOW = 105;
Dwt.WIDTH = 106;
Dwt.HEIGHT = 107;
Dwt.CLIP = 1;
Dwt.VISIBLE = 2;
Dwt.SCROLL = 3;
Dwt.FIXED_SCROLL = 4;
Dwt.Z_HIDDEN = 100;
Dwt.Z_CURTAIN = 200;
Dwt.Z_VIEW = 300;
Dwt.Z_MENU = 500;
Dwt.Z_VEIL = 600;
Dwt.Z_DIALOG = 700;
Dwt.Z_DIALOG_MENU = 750;
Dwt.Z_TOOLTIP = 775;
Dwt.Z_DND = 800;
Dwt.Z_BUSY = 900;
Dwt.Z_SPLASH = 1000;
Dwt.Z_INC = 1;
Dwt.DEFAULT = -123456789;
Dwt.LOC_NOWHERE = -10000;
Dwt.DND_DROP_NONE = 0;
Dwt.DND_DROP_COPY = 1;
Dwt.DND_DROP_MOVE = 2;
Dwt.KEY_OBJECT = "_object_";
Dwt.KEY_ID = "_id_";
Dwt._nextId = 1;
Dwt.getDomObj =
function(doc, id) {
alert("DEPRACATED: Please use document.getElementById instead");
}
Dwt.getNextId =
function() {
return "DWT" + Dwt._nextId++;
}
Dwt.associateElementWithObject =
function(domElement, jsObject) {
domElement.dwtObj = jsObject.__internalId = AjxCore.assignId(jsObject);
};
Dwt.disassociateElementFromObject =
function(domElement, jsObject) {
if (domElement){
delete domElement.dwtObj;
}
if (jsObject.__internalId){
AjxCore.unassignId(jsObject.__internalId);
}
};
Dwt.getObjectFromElement =
function(domElement) {
return AjxCore.objectWithId(domElement.dwtObj);
};
Dwt.setHandler =
function(htmlElement, event, func) {
if (event == DwtEvent.ONMOUSEWHEEL && AjxEnv.isGeckoBased) {
Dwt.clearHandler(htmlElement, event);
}
htmlElement[event] = func;
if (event == DwtEvent.ONMOUSEWHEEL && AjxEnv.isGeckoBased) {
htmlElement.addEventListener("DOMMouseScroll", func, true);
}
};
Dwt.clearHandler =
function(htmlElement, event) {
if (event == DwtEvent.ONMOUSEWHEEL && AjxEnv.isGeckoBased) {
if (htmlElement[event]) {
var func = htmlElement[event];
htmlElement.removeEventListener("DOMMouseScroll", func, true);
}
}
htmlElement[event] = null;
};
Dwt.getBackgroundRepeat =
function(htmlElement) {
return DwtCssStyle.getProperty(htmlElement, "background-repeat");
};
Dwt.setBackgroundRepeat =
function(htmlElement, style) {
htmlElement.style.backgroundRepeat = style;
};
Dwt.getBounds =
function(htmlElement, incScroll) {
var loc = Dwt.getLocation(htmlElement);
var size = Dwt.getSize(htmlElement, incScroll);
return new DwtRectangle(loc.x, loc.y, size.x, size.y);
};
Dwt.setBounds =
function(htmlElement, x, y, width, height) {
Dwt.setLocation(htmlElement, x, y);
Dwt.setSize(htmlElement, width, height);
};
Dwt.getCursor =
function(htmlElement) {
return DwtCssStyle.getProperty(htmlElement, "cursor");
};
Dwt.setCursor =
function(htmlElement, cursorName) {
htmlElement.style.cursor = cursorName;
};
Dwt.getLocation =
function(htmlElement) {
if (htmlElement.style.position == Dwt.ABSOLUTE_STYLE)
return new DwtPoint(parseInt(DwtCssStyle.getProperty(htmlElement, "left")),
parseInt(DwtCssStyle.getProperty(htmlElement, "top")));
else
return Dwt.toWindow(htmlElement, 0, 0);
};
Dwt.setLocation =
function(htmlElement, x, y) {
if (htmlElement.style.position != Dwt.ABSOLUTE_STYLE) {
DBG.println(AjxDebug.DBG1, "Cannot position static widget " + htmlElement.className);
throw new DwtException("Static widgets may not be positioned", DwtException.INVALID_OP, "Dwt.setLocation");
}
if (x = Dwt.checkPxVal(x))
htmlElement.style.left = x;
if (y = Dwt.checkPxVal(y))
htmlElement.style.top = y;
};
Dwt.checkPxVal =
function(val, check) {
if (val == Dwt.DEFAULT) return false;
if (check && val < 0 && val != Dwt.LOC_NOWHERE) {
DBG.println(AjxDebug.DBG1, "negative pixel value: " + val);
val = 0;
}
if (typeof(val) == "number")
val = val + "px";
return val;
};
Dwt.getPosition =
function(htmlElement) {
return htmlElement.style.position;
};
Dwt.setPosition =
function(htmlElement, posStyle) {
htmlElement.style.position = posStyle;
};
Dwt.getScrollStyle =
function(htmlElement) {
var overflow = DwtCssStyle.getProperty(htmlElement, "overflow");
if (overflow == "hidden")
return Dwt.CLIP;
else if (overflow =="auto")
return Dwt.SCROLL;
else if (overflow =="scroll")
return Dwt.FIXED_SCROLL;
else
return Dwt.VISIBLE;
};
Dwt.setScrollStyle =
function(htmlElement, scrollStyle) {
if (scrollStyle == Dwt.CLIP)
htmlElement.style.overflow = "hidden";
else if (scrollStyle == Dwt.SCROLL)
htmlElement.style.overflow = "auto";
else if (scrollStyle == Dwt.FIXED_SCROLL)
htmlElement.style.overflow = "scroll";
else
htmlElement.style.overflow = "visible";
};
Dwt.getSize =
function(htmlElement, incScroll) {
var p = new DwtPoint(0, 0);
if (htmlElement.offsetWidth != null) {
p.x = htmlElement.offsetWidth;
p.y = htmlElement.offsetHeight;
} else if (htmlElement.clip && htmlElement.clip.width != null) {
p.x = htmlElement.clip.width;
p.y = htmlElement.clip.height;
} else if (htmlElement.style && htmlElement.style.pixelWidth != null) {
p.x = htmlElement.style.pixelWidth;
p.y = htmlElement.style.pixelHeight;
}
p.x = parseInt(p.x);
p.y = parseInt(p.y);
return p;
};
Dwt.setSize =
function(htmlElement, width, height) {
if (width = Dwt.checkPxVal(width, true))
htmlElement.style.width = width;
if (height = Dwt.checkPxVal(height, true))
htmlElement.style.height = height;
};
Dwt.getHtmlExtent =
function(html) {
if (!Dwt._measureDiv) {
var measureDiv = document.createElement("div");
measureDiv.id = this._measureDivId = Dwt.getNextId();
Dwt.setPosition(measureDiv, Dwt.ABSOLUTE_STYLE);
Dwt.setLocation(measureDiv, Dwt.LOC_NOWHERE, Dwt.LOC_NOWHERE);
document.body.appendChild(measureDiv);
Dwt._measureDiv = measureDiv;
}
Dwt._measureDiv.innerHTML = html;
return Dwt.getSize(Dwt._measureDiv);
};
Dwt.getAttr =
function(htmlEl, attr, recursive) {
if (!recursive) {
return htmlEl && htmlEl.tagName
? (htmlEl.getAttribute(attr) || htmlEl[attr])
: null;
} else {
while (htmlEl) {
if (Dwt.getAttr(htmlEl, attr) != null) {
return htmlEl;
}
htmlEl = htmlEl.parentNode;
}
return null;
}
};
Dwt.getVisible =
function(htmlElement) {
var disp = DwtCssStyle.getProperty(htmlElement, "display");
return (disp != Dwt.DISPLAY_NONE);
};
Dwt.setVisible =
function(htmlElement, visible) {
htmlElement.style.display = visible ? Dwt.DISPLAY_BLOCK : Dwt.DISPLAY_NONE;
};
Dwt.getVisibility =
function(htmlElement) {
var vis = DwtCssStyle.getProperty(htmlElement, "visibility");
return (vis == "visible");
};
Dwt.setVisibility =
function(htmlElement, visible) {
htmlElement.style.visibility = visible ? "visible" : "hidden";
};
Dwt.setOpacity =
function(htmlElement, opacity) {
if (AjxEnv.isIE) htmlElement.style.filter = "alpha(opacity="+opacity+")";
else htmlElement.style.opacity = opacity/100;
};
Dwt.getZIndex =
function(htmlElement) {
return DwtCssStyle.getProperty(htmlElement, "z-index");
};
Dwt.setZIndex =
function(htmlElement, idx) {
htmlElement.style.zIndex = idx;
};
Dwt.getDisplay =
function(htmlElement) {
DwtCssStyle.getProperty(htmlElement, "display");
};
Dwt.setDisplay =
function(htmlElement, value) {
htmlElement.style.display = value;
};
Dwt.getWindowSize =
function() {
var p = new DwtPoint(0, 0);
if (window.innerWidth) {
p.x = window.innerWidth;
p.y = window.innerHeight;
} else if (AjxEnv.isIE6CSS) {
p.x = document.body.parentElement.clientWidth;
p.y = document.body.parentElement.clientHeight;
} else if (document.body && document.body.clientWidth) {
p.x = document.body.clientWidth;
p.y = document.body.clientHeight;
}
return p;
}
Dwt.toWindow =
function(htmlElement, x, y, containerElement, dontIncScrollTop) {
var p = new DwtPoint(x, y);
var offsetParent = htmlElement;
while (offsetParent && offsetParent != containerElement) {
p.x += offsetParent.offsetLeft;
p.y += offsetParent.offsetTop;
if (!dontIncScrollTop) {
if (offsetParent.scrollTop) {
p.y -= offsetParent.scrollTop;
}
var parentNode = offsetParent.parentNode;
while (parentNode != offsetParent.offsetParent && parentNode != containerElement) {
if (parentNode.scrollTop) {
p.y -= parentNode.scrollTop;
}
parentNode = parentNode.parentNode;
}
}
offsetParent = offsetParent.offsetParent;
}
return p;
};
Dwt.setStatus =
function(text) {
window.status = text;
};
Dwt.getTitle =
function() {
return window.document.title;
};
Dwt.setTitle =
function(text) {
window.document.title = text;
};
Dwt.getIframeDoc =
function(iframeObj) {
if (iframeObj) {
return AjxEnv.isIE
? iframeObj.contentWindow.document
: iframeObj.contentDocument;
}
return null;
};
Dwt.getIframeWindow =
function(iframeObj) {
return iframeObj.contentWindow;
};
Dwt._ffOverflowHack =
function (htmlElId, myZindex, lowThresholdZ, turnOffOverflowScroll, disableSelf) {
if (!AjxEnv.isNav)
return;
var ds = disableSelf? disableSelf: false;
var lowThresholdZIndex = lowThresholdZ? lowThresholdZ: -100;
var coll = document.getElementsByTagName("div");
var temp = null;
var len = coll.length;
var lastGoodZIndex = -1;
for (var i = 0; i < len; ++i) {
temp = coll[i];
if (temp.id == htmlElId) {
temp = coll[++i];
while(i < len && temp.style.zIndex == '') {
if (temp._oldOverflow && turnOffOverflowScroll){
temp.style.overflow = temp._oldOverflow;
delete temp._oldOverflow;
} else if (ds){
temp._oldOverflow = temp.style.overflow;
temp.style.overflow = "hidden";
}
temp = coll[++i];
}
if (i == len)
break;
}
var divZIndex = parseInt(temp.style.zIndex);
if (isNaN(divZIndex)) {
divZIndex = lastGoodZIndex;
} else {
lastGoodZIndex = divZIndex;
}
if ( divZIndex < myZindex && divZIndex >= lowThresholdZIndex) {
switch (turnOffOverflowScroll) {
case true:
if (!temp._oldOverflow) {
var cssDecl = window.getComputedStyle(temp,"");
var overflow = cssDecl.getPropertyValue("overflow");
if (AjxEnv.isFirefox1_5up && overflow == "0px") {
var overflowX = cssDecl.getPropertyValue("overflow-x");
overflow = overflowX == "hidden"
? "-moz-scrollbars-vertical"
: "-moz-scrollbars-horizontal";
}
if (overflow != 'hidden') {
temp._oldOverflow = overflow;
temp._oldScrollTop = temp.scrollTop;
temp.style.overflow = "visible";
}
}
break;
case false:
if (temp._oldOverflow) {
temp.style.overflow = temp._oldOverflow;
delete temp._oldOverflow;
}
if (temp._oldScrollTop != null) {
temp.scrollTop = temp._oldScrollTop;
}
break;
}
}
}
};
Dwt.parseHtmlFragment =
function(html, isRow) {
if (!Dwt._div)
Dwt._div = document.createElement('div');
if (isRow)
html = "<table style='table-layout:fixed'>" + html + "</table>";
Dwt._div.innerHTML = html;
return isRow ? Dwt._div.firstChild.rows[0] : Dwt._div.firstChild;
};
Dwt.contains =
function(parentEl, childEl) {
var isContained = false;
if (AjxEnv.isSafari) {
return false;
} else if (parentEl.compareDocumentPosition) {
var relPos = parentEl.compareDocumentPosition(childEl);
if ((relPos == (document.DOCUMENT_POSITION_CONTAINED_BY | document.DOCUMENT_POSITION_FOLLOWING))) {
isContained = true;
}
} else if (parentEl.contains) {
isContained = parentEl.contains(childEl);
}
return isContained;
};
Dwt.removeChildren =
function(htmlEl) {
while (htmlEl.hasChildNodes())
htmlEl.removeChild(htmlEl.firstChild);
};
Dwt.getCellIndex =
function(cell) {
if (AjxEnv.isSafari) {
if (cell.tagName && cell.tagName.toLowerCase() == "td") {
var cells = cell.parentNode.cells;
for (var i = 0; i < cells.length; i++) {
if (cells[i] == cell)
return i;
}
}
} else {
return cell.cellIndex;
}
return -1;
};
Documentation generated by
JSDoc on Thu Apr 27 13:54:33 2006