* @param {String | HTMLElement |Array} el Accepts a string to use as an ID for getting a DOM reference, an actual DOM reference, or an Array of IDs and/or HTMLElements.
* @return {HTMLElement | Array} A DOM reference to an HTML element or an array of HTMLElements.
*/
get: function(el) {
var id, nodes, c, i, len, attr;
if (el) {
if (el[NODE_TYPE] || el.item) { // Node, or NodeList
return el;
}
if (typeof el === 'string') { // id
id = el;
el = document.getElementById(el);
attr = (el) ? el.attributes : null;
if (el && attr && attr.id && attr.id.value === id) { // IE: avoid false match on "name" attribute
return el;
} else if (el && document.all) { // filter by name
el = null;
nodes = document.all[id];
for (i = 0, len = nodes.length; i < len; ++i) {
if (nodes[i].id === id) {
return nodes[i];
}
}
}
return el;
}
if (YAHOO.util.Element && el instanceof YAHOO.util.Element) {
el = el.get('element');
}
if ('length' in el) { // array-like
c = [];
for (i = 0, len = el.length; i < len; ++i) {
c[c.length] = Y.Dom.get(el[i]);
}
return c;
}
return el; // some other object, just pass it back
while ((parentNode = parentNode[OFFSET_PARENT])) {
xy[0] += parentNode[OFFSET_LEFT];
xy[1] += parentNode[OFFSET_TOP];
if (bCheck) {
xy = Y.Dom._calcBorders(parentNode, xy);
}
}
// account for any scrolled ancestors
if (Y.Dom._getStyle(node, POSITION) !== FIXED) {
parentNode = node;
while ((parentNode = parentNode[PARENT_NODE]) && parentNode[TAG_NAME]) {
scrollTop = parentNode[SCROLL_TOP];
scrollLeft = parentNode[SCROLL_LEFT];
//Firefox does something funky with borders when overflow is not visible.
if (isGecko && (Y.Dom._getStyle(parentNode, 'overflow') !== 'visible')) {
xy = Y.Dom._calcBorders(parentNode, xy);
}
if (scrollTop || scrollLeft) {
xy[0] -= scrollLeft;
xy[1] -= scrollTop;
}
}
xy[0] += docScrollLeft;
xy[1] += docScrollTop;
} else {
//Fix FIXED position -- add scrollbars
if (isOpera) {
xy[0] -= docScrollLeft;
xy[1] -= docScrollTop;
} else if (isSafari || isGecko) {
xy[0] += docScrollLeft;
xy[1] += docScrollTop;
}
}
//Round the numbers so we get sane data back
xy[0] = Math.floor(xy[0]);
xy[1] = Math.floor(xy[1]);
} else {
}
return xy;
};
}
}(), // NOTE: Executing for loadtime branching
/**
* Gets the current X position of an element based on page coordinates. The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @method getX
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements
* @return {Number | Array} The X position of the element(s)
*/
getX: function(el) {
var f = function(el) {
return Y.Dom.getXY(el)[0];
};
return Y.Dom.batch(el, f, Y.Dom, true);
},
/**
* Gets the current Y position of an element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @method getY
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements
* @return {Number | Array} The Y position of the element(s)
*/
getY: function(el) {
var f = function(el) {
return Y.Dom.getXY(el)[1];
};
return Y.Dom.batch(el, f, Y.Dom, true);
},
/**
* Set the position of an html element in page coordinates, regardless of how the element is positioned.
* The element(s) must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @method setXY
* @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements
* @param {Array} pos Contains X & Y values for new position (coordinates are page-based)
* @param {Boolean} noRetry By default we try and set the position a second time if the first fails
* Returns an ID and applies it to the element "el", if provided.
* @method generateId
* @param {String | HTMLElement | Array} el (optional) An optional element array of elements to add an ID to (no ID is added if one is already present).
* @param {String} prefix (optional) an optional prefix to use (defaults to "yui-gen").
* @return {String | Array} The generated ID, or array of generated IDs (or original ID if already present on an element)
*/
generateId: function(el, prefix) {
prefix = prefix || 'yui-gen';
var f = function(el) {
if (el && el.id) { // do not override existing ID
return el.id;
}
var id = prefix + YAHOO.env._id_counter++;
if (el) {
if (el[OWNER_DOCUMENT] && el[OWNER_DOCUMENT].getElementById(id)) { // in case one already exists
// use failed id plus prefix to help ensure uniqueness
return Y.Dom.generateId(el, id + prefix);
}
el.id = id;
}
return id;
};
// batch fails when no element, so just generate and return single ID