dom.js revision 8bf82befebcef1d93ba3945955db2e69e4adeb47
(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 setAttribute
* @param {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 {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 {HTMLElement | Array | HTMLCollection} content The content to be inserted
* @param {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: {}
};
test: function() {
try {
} catch(e) {
return false;
}
}
});
test: function() {
}
});
test: function() {
}
});
test: function() {
}
});
(function(Y) {
TABLE_OPEN = '<table>',
TABLE_CLOSE = '</table>';
// IE adds TBODY when creating TABLE elements (which may share this impl)
}
return frag;
};
}
return frag;
}
}
//Y_DOM.setAttribute(option, 'selected', 'selected');
break;
}
}
}
}
}
});
// IE: node.value changes the button text, which should be handled via innerHTML
if (!attr) {
}
}
});
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;
}
}
}
});
(function(Y) {
/**
* Add style management functionality to DOM.
* @module dom
* @submodule dom-style
* @for DOM
*/
var DOCUMENT_ELEMENT = 'documentElement',
DEFAULT_VIEW = 'defaultView',
OWNER_DOCUMENT = 'ownerDocument',
STYLE = 'style',
FLOAT = 'float',
CSS_FLOAT = 'cssFloat',
STYLE_FLOAT = 'styleFloat',
TRANSPARENT = 'transparent',
GET_COMPUTED_STYLE = 'getComputedStyle',
GET_BOUNDING_CLIENT_RECT = 'getBoundingClientRect',
TRANSFORM = 'transform',
VENDOR_TRANSFORM = [
'WebkitTransform',
'MozTransform',
'OTransform'
],
}
});
DEFAULT_UNIT: 'px',
},
/**
* Sets a style property for a given element.
* @method setStyle
* @param {HTMLElement} An HTMLElement to apply the style to.
* @param {String} att The style property to set.
* @param {String|Number} val The value.
*/
if (style) {
val = '';
}
if (att in CUSTOM_STYLES) {
return; // NOTE: return
}
att = 'cssText';
val = '';
}
}
},
/**
* Returns the current style value for the given property.
* @method getStyle
* @param {HTMLElement} An HTMLElement to get the style from.
* @param {String} att The style property to get.
*/
val = '';
if (style) {
if (att in CUSTOM_STYLES) {
}
}
}
}
return val;
},
/**
* Sets multiple style properties.
* @method setStyles
* @param {HTMLElement} node An HTMLElement to apply the styles to.
* @param {Object} hash An object literal of property:value pairs.
*/
}, Y_DOM);
},
/**
* Returns the computed style for the given node.
* @method getComputedStyle
* @param {HTMLElement} An HTMLElement to get the style from.
* @param {String} att The style property to get.
* @return {String} The computed value of the style property.
*/
var val = '',
}
return val;
}
});
// normalize reserved word float alternatives ("cssFloat" or "styleFloat")
}
// fix opera computedStyle default color unit (convert to rgb)
}
return val;
};
}
// safari converts transparent to rgba(), others use "transparent"
if (val === 'rgba(0, 0, 0, 0)') {
val = TRANSPARENT;
}
return val;
};
}
if (val === 'auto') {
val = 0;
} else {
}
}
}
return val;
};
var pos,
xy = null;
if (node) {
xy = [
];
}
}
}
}
}
return xy;
};
},
}
};
})(Y);
(function(Y) {
RE = RegExp;
Y.Color = {
KEYWORDS: {
black: '000',
silver: 'c0c0c0',
gray: '808080',
white: 'fff',
maroon: '800000',
red: 'f00',
purple: '800080',
fuchsia: 'f0f',
green: '008000',
lime: '0f0',
olive: '808000',
yellow: 'ff0',
navy: '000080',
blue: '00f',
teal: '008080',
aqua: '0ff'
},
}
val = 'rgb(' + [
}
return val;
},
val = [
];
}
}
}
}
}
return val.toUpperCase();
}
};
})(Y);
(function(Y) {
/**
* Adds position and region management functionality to DOM.
* @module dom
* @submodule dom-screen
* @for DOM
*/
var DOCUMENT_ELEMENT = 'documentElement',
COMPAT_MODE = 'compatMode',
POSITION = 'position',
FIXED = 'fixed',
RELATIVE = 'relative',
LEFT = 'left',
TOP = 'top',
_BACK_COMPAT = 'BackCompat',
MEDIUM = 'medium',
BORDER_LEFT_WIDTH = 'borderLeftWidth',
BORDER_TOP_WIDTH = 'borderTopWidth',
GET_BOUNDING_CLIENT_RECT = 'getBoundingClientRect',
GET_COMPUTED_STYLE = 'getComputedStyle',
// TODO: does caption matter?
} else {
SCROLL_NODE = 'body';
}
}
/**
* Returns the inner height of the viewport (exludes scrollbar).
* @method winHeight
* @return {Number} The current height of the viewport.
*/
return h;
},
/**
* Returns the inner width of the viewport (exludes scrollbar).
* @method winWidth
* @return {Number} The current width of the viewport.
*/
return w;
},
/**
* Document height
* @method docHeight
* @return {Number} The current height of the document.
*/
},
/**
* Document width
* @method docWidth
* @return {Number} The current width of the document.
*/
},
/**
* Amount page has been scroll horizontally
* @method docScrollX
* @return {Number} The current amount the screen is scrolled horizontally.
*/
},
/**
* Amount page has been scroll vertically
* @method docScrollY
* @return {Number} The current amount the screen is scrolled vertically.
*/
},
/**
* Gets the current 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 getXY
* @param element The target element
* @return {Array} The XY position of the element
TODO: test inDocument/display?
*/
getXY: function() {
return function(node) {
var xy = null,
box,
mode,
doc,
// inline inDoc check for perf
} else {
}
if (inDoc) {
off1 = 2;
off2 = 2;
if (mode !== _BACK_COMPAT) {
off1 = 0;
off2 = 0;
}
}
if ((mode == _BACK_COMPAT)) {
}
}
}
}
if ((scrollTop || scrollLeft)) {
}
}
} else {
}
}
return xy;
}
} else {
return function(node) { // manually calculate by crawling up offsetParents
//Calculate the Top and Left border sizes (assumes pixels)
var xy = null,
doc,
if (node) {
parentNode = node;
// TODO: refactor with !! or just falsey
if (bCheck) {
}
}
// account for any scrolled ancestors
parentNode = node;
//Firefox does something funky with borders when overflow is not visible.
}
if (scrollTop || scrollLeft) {
}
}
} else {
//Fix FIXED position -- add scrollbars
}
} else {
}
}
return xy;
};
}
}(),// NOTE: Executing for loadtime branching
/**
* Gets the current X 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 getX
* @param element The target element
* @return {Int} The X position of the element
*/
},
/**
* 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 element The target element
* @return {Int} The Y position of the element
*/
},
/**
* Set the position of an html element in page coordinates.
* The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @method setXY
* @param element The target element
* @param {Array} xy 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
*/
pos,
}
if (xy[0] !== null) {
}
if (xy[1] !== null) {
}
if (!noRetry) {
}
}
} else {
}
},
/**
* Set the X 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 setX
* @param element The target element
* @param {Int} x The X values for new position (coordinates are page-based)
*/
},
/**
* Set the Y 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 setY
* @param element The target element
* @param {Int} y The Y values for new position (coordinates are page-based)
*/
},
/**
* @method swapXY
* @description Swap the xy position with another node
* @param {Node} node The node to swap with
* @param {Node} otherNode The other node to swap with
* @return {Node}
*/
},
t = 0;
l = 0;
}
}
xy2[0] += l;
xy2[1] += t;
return xy2;
},
h = win.innerHeight,
w = win.innerWidth,
}
h = root.clientHeight;
w = root.clientWidth;
}
},
_getDocSize: function(node) {
}
}
});
})(Y);
(function(Y) {
var TOP = 'top',
RIGHT = 'right',
BOTTOM = 'bottom',
LEFT = 'left',
ret = {};
return ret;
},
/**
* Returns an Object literal containing the following about this element: (top, right, bottom, left)
* @for DOM
* @method region
* @param {HTMLElement} element The DOM element.
* @return {Object} Object literal containing the following about this element: (top, right, bottom, left)
*/
ret = false;
);
}
return ret;
},
/**
* Find the intersect information for the passes nodes.
* @method intersect
* @for DOM
* @param {HTMLElement} element The first element
* @param {HTMLElement | Object} element2 The element or region to check the interect with
* @param {Object} altRegion An object literal containing the region for the first element if we already have the data (for performance i.e. DragDrop)
* @return {Object} Object literal containing the following intersection data: (top, right, bottom, left, area, yoff, xoff, inRegion)
*/
n = node2,
off;
if (n.tagName) {
} else {
return false;
}
return {
};
},
/**
* Check if any part of this node is in the passed region
* @method inRegion
* @for DOM
* @param {Object} node2 The node to get the region from or an Object literal of the region
* $param {Boolean} all Should all of the node be inside the region
* @param {Object} altRegion An object literal containing the region for this node if we already have the data (for performance i.e. DragDrop)
* @return {Boolean} True if in region, false if not.
*/
var region = {},
n = node2,
off;
if (n.tagName) {
} else {
return false;
}
if (all) {
return (
} else {
return true;
} else {
return false;
}
}
},
/**
* Check if any part of this element is in the viewport
* @method inViewportRegion
* @for DOM
* @param {HTMLElement} element The DOM element.
* @param {Boolean} all Should all of the node be inside the region
* @param {Object} altRegion An object literal containing the region for this node if we already have the data (for performance i.e. DragDrop)
* @return {Boolean} True if in region, false if not.
*/
},
_getRegion: function(t, r, b, l) {
var region = {};
return region;
},
/**
* Returns an Object literal containing the following about the visible region of viewport: (top, right, bottom, left)
* @method viewportRegion
* @for DOM
* @return {Object} Object literal containing the following about the visible region of the viewport: (top, right, bottom, left)
*/
viewportRegion: function(node) {
var ret = false,
if (node) {
scrollX); // left
}
return ret;
}
});
})(Y);
YUI.add('dom', function(Y){}, '@VERSION@' ,{use:['dom-base', 'dom-style', 'dom-screen', 'selector']});