dom-base.js revision db445e900d0225be4de71ea099e90c2a0ad12921
(function(Y) {
/**
* The DOM utility provides a cross-browser abtraction layer
* normalizing DOM tasks, and adds extra helper functionality
* for other common tasks.
* @module dom
* @submodule dom-base
* @for DOM
*
*/
/**
* Provides DOM helper methods.
* @class DOM
*
*/
var NODE_TYPE = 'nodeType',
OWNER_DOCUMENT = 'ownerDocument',
DOCUMENT_ELEMENT = 'documentElement',
DEFAULT_VIEW = 'defaultView',
PARENT_WINDOW = 'parentWindow',
TAG_NAME = 'tagName',
PARENT_NODE = 'parentNode',
FIRST_CHILD = 'firstChild',
PREVIOUS_SIBLING = 'previousSibling',
NEXT_SIBLING = 'nextSibling',
CONTAINS = 'contains',
COMPARE_DOCUMENT_POSITION = 'compareDocumentPosition',
EMPTY_STRING = '',
EMPTY_ARRAY = [],
re_tag = /<([a-z]+)/i,
ret = true;
ret = false;
}
return ret;
},
Y_DOM = {
/**
* Returns the HTMLElement with the given ID (Wrapper for document.getElementById).
* @method byId
* @param {String} id the id attribute
* @param {Object} doc optional The document to search. Defaults to current document
* @return {HTMLElement | null} The HTMLElement with the id, or null if none found.
*/
// handle dupe IDs and IE name collision
},
/**
* Returns the text content of the HTMLElement.
* @method getText
* @param {HTMLElement} element The html element.
* @return {String} The text content of the element (includes text of any descending elements).
*/
function(element) {
var ret = '';
if (element) {
}
return ret || '';
} : function(element) {
var ret = '';
if (element) {
}
return ret || '';
},
/**
* Sets the text content of the HTMLElement.
* @method setText
* @param {HTMLElement} element The html element.
* @param {String} content The content to add.
*/
if (element) {
}
if ('innerText' in element) {
} else if ('nodeValue' in element) {
}
},
/*
* Finds the ancestor of the element.
* @method ancestor
* @param {HTMLElement} element The html element.
* @param {Function} fn optional An optional boolean test to apply.
* The optional function is passed the current DOM node being tested as its only argument.
* If no function is given, the parentNode is returned.
* @param {Boolean} testSelf optional Whether or not to include the element in the scan
* @return {HTMLElement | null} The matching DOM node or null if none found.
*/
var ret = null;
if (testSelf) {
}
},
/*
* Finds the ancestors of the element.
* @method ancestors
* @param {HTMLElement} element The html element.
* @param {Function} fn optional An optional boolean test to apply.
* The optional function is passed the current DOM node being tested as its only argument.
* If no function is given, all ancestors are returned.
* @param {Boolean} testSelf optional Whether or not to include the element in the scan
* @return {Array} An array containing all matching DOM nodes.
*/
if (ancestor) {
}
}
return ret;
},
/**
* Searches the element by the given axis for the first matching element.
* @method elementByAxis
* @param {HTMLElement} element The html element.
* @param {String} axis The axis to search (parentNode, nextSibling, previousSibling).
* @param {Function} fn optional An optional boolean test to apply.
* @param {Boolean} all optional Whether all node types should be returned, or just element nodes.
* The optional function is passed the current HTMLElement being tested as its only argument.
* If no function is given, the first element is returned.
* @return {HTMLElement | null} The matching element or null if none found.
*/
return element;
}
}
return null;
},
/**
* Determines whether or not one HTMLElement is or contains another HTMLElement.
* @method contains
* @param {HTMLElement} element The containing html element.
* @param {HTMLElement} needle The html element that may be contained.
* @return {Boolean} Whether or not the element is or contains the needle.
*/
var ret = false;
ret = false;
if (Y.UA.opera || needle[NODE_TYPE] === 1) { // IE & SAF contains fail if needle not an ELEMENT_NODE
} else {
}
ret = true;
}
}
return ret;
},
/**
* Determines whether or not the HTMLElement is part of the document.
* @method inDoc
* @param {HTMLElement} element The containing html element.
* @param {HTMLElement} doc optional The document to check.
* @return {Boolean} Whether or not the element is attached to the document.
*/
var ret = false,
// contains only works with HTML_ELEMENT
} else {
}
}
return ret;
},
var nodes = [],
ret = [],
i,
node;
if (root.querySelectorAll) {
if (nodes) {
// root.all may return HTMLElement or HTMLCollection.
// some elements are also HTMLCollection (FORM, SELECT).
} else { // prep for filtering
}
}
// filter out matches on node.name
// and element.id as reference to element with id === 'id'
}
}
}
}
} else {
}
return ret;
},
/**
* Creates a new dom node using the provided markup string.
* @method create
* @param {String} html The markup used to create the element
* @param {HTMLDocument} doc An optional document context
* @return {HTMLElement|DocumentFragment} returns a single HTMLElement
* when creating one node, and a documentFragment when creating
* multiple nodes.
*/
if (typeof html === 'string') {
}
ret = null,
if (m && m[1]) {
if (typeof creator === 'function') {
} else {
}
}
} else if (nodes[0] && nodes[0].className === 'yui3-big-dummy') { // using dummy node to preserve some attributes (e.g. OPTION not selected)
} else {
}
} else { // return multiple nodes as a fragment
}
}
return ret;
},
var ret = null,
i, len;
}
}
} // else inline with log for minification
return ret;
},
'for': 'htmlFor',
'class': 'className'
} : { // w3c
'htmlFor': 'for',
'className': 'class'
},
/**
* Provides a normalized attribute interface.
* @method setAttibute
* @param {String | HTMLElement} el The target element for the attribute.
* @param {String} attr The attribute to set.
* @param {String} val The value of the attribute.
*/
}
},
/**
* Provides a normalized attribute interface.
* @method getAttibute
* @param {String | HTMLElement} el The target element for the attribute.
* @param {String} attr The attribute to get.
* @return {String} The current value of the attribute.
*/
var ret = '';
if (ret === null) {
}
}
return ret;
},
},
_fragClones: {},
if (frag) {
} else {
}
return frag;
},
_removeChildNodes: function(node) {
while (node.firstChild) {
}
},
/**
* Inserts content in a node at the given location
* @method addHTML
* @param {HTMLElement} node The node to insert into
* @param {String | HTMLElement | Array | HTMLCollection} content The content to be inserted
* @param {String | HTMLElement} where Where to insert the content
* If no "where" is given, content is appended to the node
* Possible values for "where"
* <dl>
* <dt>HTMLElement</dt>
* <dd>The element to insert before</dd>
* <dt>"replace"</dt>
* <dd>Replaces the existing HTML</dd>
* <dt>"before"</dt>
* <dd>Inserts before the existing HTML</dd>
* <dt>"before"</dt>
* <dd>Inserts content before the node</dd>
* <dt>"after"</dt>
* <dd>Inserts content after the node</dd>
* </dl>
*/
i = 0,
item,
}
}
}
if (where) {
} else {
switch (where) {
case 'replace':
while (node.firstChild) {
}
if (newNode) { // allow empty content to clear node
}
break;
case 'before':
break;
case 'after':
} else {
}
break;
default:
}
}
} else if (newNode) {
}
return ret;
},
VALUE_SETTERS: {},
VALUE_GETTERS: {},
if (getter) {
} else {
}
}
// workaround for IE8 JSON stringify bug
// which converts empty string values to null
if (ret === EMPTY_STRING) {
}
},
var setter;
if (setter) {
} else {
}
}
},
var nodes = [],
}
}
}
}
return nodes;
},
/**
* Brute force version of contains.
* Used for browsers without contains support for non-HTMLElement Nodes (textNodes, etc).
* @method _bruteContains
* @private
* @param {HTMLElement} element The containing html element.
* @param {HTMLElement} needle The html element that may be contained.
* @return {Boolean} Whether or not the element is or contains the needle.
*/
while (needle) {
return true;
}
}
return false;
},
// TODO: move to Lang?
/**
* Memoizes dynamic regular expressions to boost runtime performance.
* @method _getRegExp
* @private
* @param {String} str The string to convert to a regular expression.
* @param {String} flags optional An optinal string of flags.
* @return {RegExp} An instance of RegExp
*/
}
},
/**
* returns the appropriate document.
* @method _getDoc
* @private
* @param {HTMLElement} element optional Target element.
* @return {Object} The document for the given element or the default document.
*/
if (element) {
}
return doc;
},
/**
* returns the appropriate window.
* @method _getWin
* @private
* @param {HTMLElement} element optional Target element.
* @return {Object} The window for the given element or the default window.
*/
},
var result,
i = 0,
node,
ret;
if (typeof result !== 'undefined') {
}
}
}
},
}
if (node.parentNode) {
}
},
if (parent) {
if (grandparent) {
}
} else {
}
}
},
generateID: function(el) {
if (!id) {
}
return id;
},
creators: {}
};
(function(Y) {
TABLE_OPEN = '<table>',
TABLE_CLOSE = '</table>';
// IE adds TBODY when creating TABLE elements (which may share this impl)
}
return frag;
},
return frag;
}
}, true);
}
});
// IE: node.value changes the button text, which should be handled via innerHTML
if (!attr) {
}
},
break;
}
}
}
});
}
return create('<select><option class="yui3-big-dummy" selected></option>' + html + '</select>', doc);
},
},
},
},
tbody: 'table'
});
legend: 'fieldset',
});
}
},
// TODO: implement multipe select
} else {
}
}
return val;
}
});
})(Y);
})(Y);
/**
* Determines whether a DOM element has the given className.
* @method hasClass
* @for DOM
* @param {HTMLElement} element The DOM element.
* @param {String} className the class name to search for
* @return {Boolean} Whether or not the element has the given class.
*/
},
/**
* Adds a class name to a given DOM element.
* @method addClass
* @for DOM
* @param {HTMLElement} element The DOM element.
* @param {String} className the class name to add to the class attribute
*/
}
},
/**
* Removes a class name from a given element.
* @method removeClass
* @for DOM
* @param {HTMLElement} element The DOM element.
* @param {String} className the class name to remove from the class attribute
*/
}
}
},
/**
* Replace a class with another class for a given element.
* If no oldClassName is present, the newClassName is simply added.
* @method replaceClass
* @for DOM
* @param {HTMLElement} element The DOM element
* @param {String} oldClassName the class name to be replaced
* @param {String} newClassName the class name that will be replacing the old class name
*/
},
/**
* If the className exists on the node it is removed, if it doesn't exist it is added.
* @method toggleClass
* @for DOM
* @param {HTMLElement} element The DOM element
* @param {String} className the class name to be toggled
* @param {Boolean} addClass optional boolean to indicate whether class
* should be added or removed regardless of current state
*/
if (add) {
} else {
}
}
});
/**
* Sets the width of the element to the given size, regardless
* of box model, border, padding, etc.
* @method setWidth
* @param {HTMLElement} element The DOM element.
* @param {String|Int} size The pixel height to size to
*/
},
/**
* Sets the height of the element to the given size, regardless
* of box model, border, padding, etc.
* @method setHeight
* @param {HTMLElement} element The DOM element.
* @param {String|Int} size The pixel height to size to
*/
},
var size = 0;
if (val < 0) {
val = 0;
}
}
}
});