dom-base-debug.js revision 48e05d4731f078dd4c07a6770b2f09e10419b7fe
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major(function(Y) {
c5aaf8bd167dc5fc4175bf9fc2d5b8067b913880Neil Madden * The DOM utility provides a cross-browser abtraction layer
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * normalizing DOM tasks, and adds extra helper functionality
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * for other common tasks.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @module dom
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @submodule dom-base
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * Provides DOM helper methods.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @class DOM
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major COMPARE_DOCUMENT_POSITION = 'compareDocumentPosition',
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major re_tag = /<([a-z]+)/i,
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * Returns the HTMLElement with the given ID (Wrapper for document.getElementById).
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @method byId
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {String} id the id attribute
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {Object} doc optional The document to search. Defaults to current document
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @return {HTMLElement | null} The HTMLElement with the id, or null if none found.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major // handle dupe IDs and IE name collision
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major // @deprecated
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major // @deprecated
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major return ret || null;
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * Returns the text content of the HTMLElement.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @method getText
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {HTMLElement} element The html element.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @return {String} The text content of the element (includes text of any descending elements).
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major getText: (documentElement.textContent !== undefined) ?
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major } : function(element) {
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major ret = element.innerText || element.nodeValue; // might be a textNode
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * Sets the text content of the HTMLElement.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @method setText
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {HTMLElement} element The html element.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {String} content The content to add.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major setText: (documentElement.textContent !== undefined) ?
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * Finds the previous sibling of the element.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @method previous
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @deprecated Use elementByAxis
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {HTMLElement} element The html element.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {Function} fn optional An optional boolean test to apply.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * The optional function is passed the current DOM node being tested as its only argument.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * If no function is given, the first sibling is returned.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {Boolean} all optional Whether all node types should be scanned, or just element nodes.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @return {HTMLElement | null} The matching DOM node or null if none found.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major return Y_DOM.elementByAxis(element, PREVIOUS_SIBLING, fn, all);
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * Finds the next sibling of the element.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @method next
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @deprecated Use elementByAxis
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {HTMLElement} element The html element.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {Function} fn optional An optional boolean test to apply.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * The optional function is passed the current DOM node being tested as its only argument.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * If no function is given, the first sibling is returned.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {Boolean} all optional Whether all node types should be scanned, or just element nodes.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @return {HTMLElement | null} The matching DOM node or null if none found.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major return Y_DOM.elementByAxis(element, NEXT_SIBLING, fn, all);
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * Finds the ancestor of the element.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @method ancestor
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {HTMLElement} element The html element.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {Function} fn optional An optional boolean test to apply.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * The optional function is passed the current DOM node being tested as its only argument.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * If no function is given, the parentNode is returned.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {Boolean} testSelf optional Whether or not to include the element in the scan
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @return {HTMLElement | null} The matching DOM node or null if none found.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major return ret || Y_DOM.elementByAxis(element, PARENT_NODE, fn, null);
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * Finds the ancestors of the element.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @method ancestors
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {HTMLElement} element The html element.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @param {Function} fn optional An optional boolean test to apply.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * The optional function is passed the current DOM node being tested as its only argument.
87e1cbcd02820f55e1816ee4efe9e9127be22a11James Phillpotts * If no function is given, all ancestors are returned.
87e1cbcd02820f55e1816ee4efe9e9127be22a11James Phillpotts * @param {Boolean} testSelf optional Whether or not to include the element in the scan
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major * @return {Array} An array containing all matching DOM nodes.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major var ancestor = Y_DOM.ancestor.apply(Y_DOM, arguments),
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major while ((ancestor = Y_DOM.ancestor(ancestor, fn))) {
8b6198b1170e3128c5df83267597f0058d07c70dJames Phillpotts * Searches the element by the given axis for the first matching element.
8b6198b1170e3128c5df83267597f0058d07c70dJames Phillpotts * @method elementByAxis
8b6198b1170e3128c5df83267597f0058d07c70dJames Phillpotts * @param {HTMLElement} element The html element.
8b6198b1170e3128c5df83267597f0058d07c70dJames Phillpotts * @param {String} axis The axis to search (parentNode, nextSibling, previousSibling).
8b6198b1170e3128c5df83267597f0058d07c70dJames Phillpotts * @param {Function} fn optional An optional boolean test to apply.
921c9e8e47accb592cc0dcda4f6973aabc1935ceNeil Madden * @param {Boolean} all optional Whether all node types should be returned, or just element nodes.
921c9e8e47accb592cc0dcda4f6973aabc1935ceNeil Madden * The optional function is passed the current HTMLElement being tested as its only argument.
921c9e8e47accb592cc0dcda4f6973aabc1935ceNeil Madden * If no function is given, the first element is returned.
921c9e8e47accb592cc0dcda4f6973aabc1935ceNeil Madden * @return {HTMLElement | null} The matching element or null if none found.
e8721886dbfd32e88cc7077cbee4b6bb1b44b443Peter Major elementByAxis: function(element, axis, fn, all) {
return element;
var ret = false;
ret = false;
if (Y.UA.opera || needle[NODE_TYPE] === 1) { // IE & SAF contains fail if needle not an ELEMENT_NODE
ret = true;
return ret;
var ret = false,
return ret;
var nodes = [],
ret = [],
node;
return ret;
ret = null,
} else if (nodes[0] && nodes[0].className === 'yui3-big-dummy') { // using dummy node to preserve some attributes (e.g. OPTION not selected)
return ret;
var ret = null,
i, len;
return ret;
if (ret === null) {
return ret;
_fragClones: {},
if (frag) {
return frag;
item,
if (where) {
switch (where) {
} else if (newNode) {
return ret;
VALUE_SETTERS: {},
VALUE_GETTERS: {},
if (getter) {
var setter;
if (setter) {
var nodes = [],
return nodes;
while (needle) {
if (element) {
return doc;
var result,
node,
ret;
if (parent) {
if (grandparent) {
creators: {}
return frag;
return frag;
if (!attr) {
return create('<select><option class="yui3-big-dummy" selected></option>' + html + '</select>', doc);
return val;
if (add) {