dom.js revision 14dc4f889a7b6c39f10aa490ea3c4c69de5e99bb
* Returns the HTMLElement with the given ID (Wrapper for document.getElementById). * @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. * @param {HTMLElement} element The html element. * @return {String} The text content of the element (includes text of any descending elements). * Sets the text content of the HTMLElement. * @param {HTMLElement} element The html element. * @param {String} content The content to add. }
else if (
'nodeValue' in element) {
* Finds the ancestor of the element. * @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. * Finds the ancestors of the element. * @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. * Searches the element by the given axis for the first matching element. * @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. * Determines whether or not one HTMLElement is or contains another HTMLElement. * @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. * Determines whether or not the HTMLElement is part of the document. * @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. // contains only works with HTML_ELEMENT for (i =
0;
node =
nodes[i++];) {
// check for a match * Creates a new dom node using the provided markup string. * @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 if (
typeof html ===
'string') {
if (
typeof custom[m[
1]] ===
'function') {
if (
nodes.
length ===
1) {
// return single node, breaking parentNode ref from "fragment" }
else if (
nodes[
0] &&
nodes[
0].
className ===
'yui3-big-dummy') {
// using dummy node to preserve some attributes (e.g. OPTION not selected) }
else {
// return multiple nodes as a fragment if (
nodes.
item) {
// convert live list to static array }
// else inline with log for minification else { Y.
log(
'unable to convert ' +
nodes +
' to fragment',
'warn',
'dom'); }
* Provides a normalized attribute interface. * @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. else { Y.
log(
'bad input to setAttribute',
'warn',
'dom'); }
* Provides a normalized attribute interface. * @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. ret =
'';
// per DOM spec else { Y.
log(
'bad input to getAttribute',
'warn',
'dom'); }
* Inserts content in a node at the given location * @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" * <dd>The element to insert before</dd> * <dd>Replaces the existing HTML</dd> * <dd>Inserts before the existing HTML</dd> * <dd>Inserts content before the node</dd> * <dd>Inserts content after the node</dd> }
else if (
typeof content ==
'string' ||
typeof content ==
'number') {
if (
where.
nodeType) {
// insert regardless of relationship to node if (
newNode) {
// allow empty content to clear node var ret =
'',
// TODO: return null? // workaround for IE8 JSON stringify bug // which converts empty string values to null return (
typeof ret ===
'string') ?
ret :
'';
* Brute force version of contains. * Used for browsers without contains support for non-HTMLElement Nodes (textNodes, etc). * @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. * Memoizes dynamic regular expressions to boost runtime performance. * @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. * @param {HTMLElement} element optional Target element. * @return {Object} The document for the given element or the default document. * returns the appropriate window. * @param {HTMLElement} element optional Target element. * @return {Object} The window for the given element or the default window. if (
typeof result !==
'undefined') {
// IE adds TBODY when creating TABLE elements (which may share this impl) // IE: node.value changes the button text, which should be handled via innerHTML return create(
'<select><option class="yui3-big-dummy" selected></option>' +
html +
'</select>',
doc);
// TODO: implement multipe select Y.
log(
'multiple select normalization not implemented',
'warn',
'DOM');