node-debug.js revision 4234bd66390838463bb0eb8d54bc1a098604e0c3
/**
* The Node Utility provides a DOM-like interface for interacting with DOM nodes.
* @module node
* @submodule node-base
*/
/**
* The NodeList class provides a wrapper for manipulating DOM NodeLists.
* Use Y.get() to retrieve NodeList instances.
*
* <strong>NOTE:</strong> NodeList properties are accessed using
* the <code>set</code> and <code>get</code> methods.
*
* @class NodeList
* @constructor
*/
// "globals"
var g_nodes = {},
g_restrict = {},
DOT = '.',
NODE_NAME = 'nodeName',
NODE_TYPE = 'nodeType',
OWNER_DOCUMENT = 'ownerDocument',
TAG_NAME = 'tagName',
UID = '_yuid',
SuperConstr = Y.Base,
if (config.restricted) {
g_restrict[this[UID]] = true;
}
},
var ret = null;
if (fn) {
function(n) {
} :
function(n) {
};
}
return ret;
};
// end "globals"
Node.DOM_EVENTS = {
'click': true,
'dblclick': true,
'keydown': true,
'keypress': true,
'keyup': true,
'mousedown': true,
'mousemove': true,
'mouseout': true,
'mouseover': true,
'mouseup': true,
'focus': true,
'blur': true,
'submit': true,
'change': true,
'error': true,
'load': true,
'mouseenter': true,
'mouseleave': true
};
Node._instances = {};
/**
* Retrieves the DOM node bound to a Node instance
* @method getDOMNode
* @static
*
* @param {Y.Node || HTMLNode} node The Node instance or an HTMLNode
* @return {HTMLNode} The DOM node bound to the Node instance. If a DOM node is passed
* as the node argument, it is simply returned.
*/
if (node) {
node = null;
}
}
return node || null;
};
var isWindow = false;
val = null; // not allowed to go outside of root node
} else {
}
} else if (val.item || // dom collection or Node instance // TODO: check each node for restrict? block ancestor?
} else {
if (depth > 0) {
for (var i in val) { // TODO: test this and pull hasOwnProperty check if safe?
}
}
}
}
}
}
return val;
};
ret;
}
return ret;
};
} else {
}
};
if (typeof name === 'string') {
} else {
});
}
};
var instance = null;
if (typeof node === 'string') {
} else {
}
}
if (node) {
if (!instance) {
});
} else if (restrict) {
}
}
// TODO: restrict on subsequent call?
return instance;
};
};
text: {
getter: function() {
},
readOnly: true
},
'options': {
getter: function() {
return this.getElementsByTagName('option');
}
},
/**
* Returns a NodeList instance.
* @property children
* @type NodeList
*/
'children': {
getter: function() {
childNodes, i, len;
children = [];
if (childNodes[i][TAG_NAME]) {
}
}
}
}
},
value: {
getter: function() {
},
}
},
restricted: {
writeOnce: true,
value: false
}
};
// call with instance context
} else {
}
return this;
};
// call with instance context
val;
} else {
}
};
toString: function() {
var str = '',
if (node) {
}
}
// TODO: add yuid?
}
},
_addDOMAttr: function(attr) {
getter: function() {
},
}
});
} else {
}
},
var args;
ret = null;
} else {
}
return ret;
},
/**
* Detaches a DOM event handler.
* @method detach
* @param {String} type The type of DOM Event
* @param {Function} fn The handler to call when the event fires
*/
} else {
}
return ret;
},
},
this._addDOMAttr(attr);
} else {
}
}
},
this._addDOMAttr(attr);
} else {
}
}
},
/**
* Compares nodes to determine if they match.
* @method compareTo
* @param {HTMLElement | Node} refNode The reference node to compare to the node.
* @return {Boolean} True if the nodes match, false if they do not.
*/
}
},
/**
* Determines whether the node is appended to the document.
* @method inDoc
* @param {Node|HTMLElement} doc optional An optional document to check against.
* Defaults to current document.
* @return {Boolean} Whether or not this node is appended to the document.
*/
if (doc.documentElement) {
}
},
} else {
ret = null;
}
return ret;
},
/**
* Returns the nearest ancestor that passes the test applied by supplied boolean method.
* @method ancestor
* @param {String | Function} fn A selector or boolean method for testing elements.
* If a function is used, it receives the current node being tested as the only argument.
* @return {Node} The matching Node instance or null if not found
*/
},
/**
* Returns the previous matching sibling.
* Returns the nearest element node sibling if no method provided.
* @method previous
* @param {String | Function} fn A selector or boolean method for testing elements.
* If a function is used, it receives the current node being tested as the only argument.
* @param {Boolean} all optional Whether all node types should be returned, or just element nodes.
* @return {Node} Node instance or null if not found
*/
},
/**
* Returns the next matching sibling.
* Returns the nearest element node sibling if no method provided.
* @method next
* @param {String | Function} fn A selector or boolean method for testing elements.
* If a function is used, it receives the current node being tested as the only argument.
* @param {Boolean} all optional Whether all node types should be returned, or just element nodes.
* @return {Node} Node instance or null if not found
*/
},
/**
* Retrieves a Node instance of nodes based on the given CSS selector.
* @method query
*
* @param {string} selector The CSS selector to test against.
* @return {Node} A Node instance for the matching HTMLElement.
*/
},
/**
* Retrieves a nodeList based on the given CSS selector.
* @method queryAll
*
* @param {string} selector The CSS selector to test against.
* @return {NodeList} A NodeList instance for the matching HTMLCollection/Array.
*/
},
// TODO: allow fn test
/**
* Test if the supplied node matches the supplied selector.
* @method test
*
* @param {string} selector The CSS selector to test against.
* @return {boolean} Whether or not the node matches the selector.
*/
},
/**
* Removes the node from its parent.
* Shortcut for myNode.get('parentNode').removeChild(myNode);
* @method remove
* @chainable
*
*/
remove: function() {
return this;
},
// TODO: safe enough?
ret;
if (a && a instanceof Y.Node) {
a = Node.getDOMNode(a);
}
if (b && b instanceof Y.Node) {
b = Node.getDOMNode(b);
}
},
destructor: function() {
delete g_restrict[uid];
},
/**
* Applies the given function to each Node in the NodeList.
* @method each
* @deprecated Use NodeList
* @param {Function} fn The function to apply
* @param {Object} context optional An optional context to apply the function with
* Default context is the NodeList instance
* @return {NodeList} NodeList containing the updated collection
* @chainable
*/
},
/**
* Retrieves the Node instance at the given index.
* @method item
* @deprecated Use NodeList
*
* @param {Number} index The index of the target Node.
* @return {Node} The Node instance at the given index.
*/
return this;
},
/**
* Returns the current number of items in the Node.
* @method size
* @deprecated Use NodeList
* @return {Int} The number of items in the Node.
*/
size: function() {
},
addEventListener: function() {
},
removeEventListener: function() {
},
// TODO: need this?
}
}, true);
/**
* The NodeList Utility provides a DOM-like interface for interacting with DOM nodes.
* @module node
* @submodule node-list
*/
/**
* The NodeList class provides a wrapper for manipulating DOM NodeLists.
* Use Y.get() to retrieve NodeList instances.
*
* <strong>NOTE:</strong> NodeList properties are accessed using
* the <code>set</code> and <code>get</code> methods.
*
* @class NodeList
* @constructor
*/
Y.Array._diff = function(a, b) {
var removed = [],
present = false,
present = false;
if (a[i] === b[j]) {
present = true;
continue outer;
}
}
if (!present) {
}
}
return removed;
};
Y.Array.diff = function(a, b) {
return {
};
};
// "globals"
var g_nodelists = {},
UID = '_yuid',
if (typeof nodes === 'string') {
}
Y.stamp(this);
if (config.restricted) {
g_restrict = this[UID];
}
};
// end "globals"
/**
* Retrieves the DOM nodes bound to a NodeList instance
* @method getDOMNodes
* @static
*
* @param {Y.NodeList} node The NodeList instance
* @return {Array} The array of DOM nodes bound to the NodeList
*/
};
NodeList._instances = [];
} else {
}
};
var ret = [],
ctx,
if (!instance) {
}
}
});
// TODO: remove tmp pointer
};
} else {
}
};
if (typeof name === 'string') {
} else {
});
}
};
NodeList._getTempNode = function() {
if (!tmp) {
}
return tmp;
};
// call with instance context
if (!instance) {
}
});
};
// call with instance context
ret = [];
if (!instance) { // reuse tmp instance
}
});
return ret;
};
/**
* Retrieves the Node instance at the given index.
* @method item
*
* @param {Number} index The index of the target Node.
* @return {Node} The Node instance at the given index.
*/
},
/**
* Applies the given function to each Node in the NodeList.
* @method each
* @param {Function} fn The function to apply
* @param {Object} context optional An optional context to apply the function with
* Default context is the NodeList instance
* @return {NodeList} NodeList containing the updated collection
* @chainable
*/
var instance = this;
});
return instance;
},
/**
* Filters the NodeList instance down to only nodes matching the given selector.
* @method filter
* @param {String} selector The selector to filter against
* @return {NodeList} NodeList containing the updated collection
* @see Selector
*/
},
//if (!this.attrAdded(attr)) {
//this._addAttr(attr);
//return NodeList.DEFAULT_GETTER.call(this, attr);
}
},
}
},
}
},
destructor: function() {
},
plug: function() {
});
return this;
},
unplug: function() {
});
return this;
},
refresh: function() {
var doc,
diff,
if (this._query) {
if (g_nodelists[this[UID]] &&
}
}
return this;
},
/**
* Returns the current number of items in the NodeList.
* @method size
* @return {Int} The number of items in the NodeList.
*/
size: function() {
},
toString: function() {
var str = '',
node;
}
}
}
}
},
getter: function() {
},
}
});
}
}, true);
'addEventListener',
'removeEventListener',
'remove'
]);
// TODO: propagate restricted to nodes?
});
// zero-length result returns null
return nodeList;
};
var UID = '_yuid';
Y.Array.each([
/**
* Passes through to DOM method.
* @method replaceChild
* @param {HTMLElement | Node} node Node to be inserted
* @param {HTMLElement | Node} refNode Node to be replaced
* @return {Node} The replaced node
*/
'replaceChild',
/**
* Passes through to DOM method.
* @method appendChild
* @param {HTMLElement | Node} node Node to be appended
* @return {Node} The appended node
*/
'appendChild',
/**
* Passes through to DOM method.
* @method insertBefore
* @param {HTMLElement | Node} newNode Node to be appended
* @param {HTMLElement | Node} refNode Node to be inserted before
* @return {Node} The inserted node
*/
'insertBefore',
/**
* Passes through to DOM method.
* @method removeChild
* @param {HTMLElement | Node} node Node to be removed
* @return {Node} The removed node
*/
'removeChild',
/**
* Passes through to DOM method.
* @method hasChildNodes
* @return {Boolean} Whether or not the node has any childNodes
*/
'hasChildNodes',
/**
* Passes through to DOM method.
* @method cloneNode
* @param {HTMLElement | Node} node Node to be cloned
* @return {Node} The clone
*/
'cloneNode',
/**
* Passes through to DOM method.
* @method hasAttribute
* @param {String} attribute The attribute to test for
* @return {Boolean} Whether or not the attribute is present
*/
'hasAttribute',
/**
* Passes through to DOM method.
* @method removeAttribute
* @param {String} attribute The attribute to be removed
* @chainable
*/
'removeAttribute',
/**
* Passes through to DOM method.
* @method scrollIntoView
* @chainable
*/
'scrollIntoView',
/**
* Passes through to DOM method.
* @method getElementsByTagName
* @param {String} tagName The tagName to collect
* @return {NodeList} A NodeList representing the HTMLCollection
*/
'getElementsByTagName',
/**
* Passes through to DOM method.
* @method focus
* @chainable
*/
'focus',
/**
* Passes through to DOM method.
* @method blur
* @chainable
*/
'blur',
/**
* Passes through to DOM method.
* Only valid on FORM elements
* @method submit
* @chainable
*/
'submit',
/**
* Passes through to DOM method.
* Only valid on FORM elements
* @method reset
* @chainable
*/
'reset',
/**
* Passes through to DOM method.
* @method select
* @chainable
*/
'select'
], function(method) {
return ret;
};
});
/**
* Determines whether the ndoe is an ancestor of another HTML element in the DOM hierarchy.
* @method contains
* @chainable
* @param {Node | HTMLElement} needle The possible node or descendent
* @return {Boolean} Whether or not this node is the needle its ancestor
*/
'contains',
/**
* Normalizes troublesome attributes
* @chainable
* @method setAttribute
* @param {string} name The attribute name
* @param {string} value The value to set
*/
'setAttribute',
/**
* Normalizes troublesome attributes
* @chainable
* @method getAttribute
* @param {string} name The attribute name
* @return {string} The attribute value
*/
'getAttribute',
'insertHTML'
]);
};
}
(function() { // IE clones expandos; regenerate UID
};
}
})();
/**
* Extended Node interface for managing classNames.
* @module node
* @submodule node
* @for Node
*/
var methods = [
/**
* Determines whether the node has the given className.
* @method hasClass
* @param {String} className the class name to search for
* @return {Boolean} Whether or not the node has the given class.
*/
'hasClass',
/**
* Adds a class name to the node.
* @method addClass
* @param {String} className the class name to add to the node's class attribute
* @chainable
*/
'addClass',
/**
* Removes a class name from the node.
* @method removeClass
* @param {String} className the class name to remove from the node's class attribute
* @chainable
*/
'removeClass',
/**
* Replace a class with another class.
* If no oldClassName is present, the newClassName is simply added.
* @method replaceClass
* @param {String} oldClassName the class name to be replaced
* @param {String} newClassName the class name that will be replacing the old class name
* @chainable
*/
'replaceClass',
/**
* If the className exists on the node it is removed, if it doesn't exist it is added.
* @method toggleClass
* @param {String} className the class name to be toggled
* @chainable
*/
'toggleClass'
];
/**
* Extended Node interface for managing node styles.
* @module node
* @submodule node-style
* @for Node
*/
var methods = [
/**
* Returns the style's current value.
* @method getStyle
* @param {String} attr The style attribute to retrieve.
* @return {String} The current value of the style property for the element.
*/
'getStyle',
/**
* Returns the computed value for the given style property.
* @method getComputedStyle
* @param {String} attr The style attribute to retrieve.
* @return {String} The computed value of the style property for the element.
*/
'getComputedStyle',
/**
* Sets a style property of the node.
* @method setStyle
* @param {String} attr The style attribute to set.
* @param {String|Number} val The value.
* @chainable
*/
'setStyle',
/**
* Sets multiple style properties on the node.
* @method setStyles
* @param {Object} hash An object literal of property:value pairs.
* @chainable
*/
'setStyles'
];
/**
* Extended Node interface for managing regions and screen positioning.
* Adds support for positioning elements and normalizes window size and scroll detection.
* @module node
* @submodule node-screen
* @for Node
*/
var NODE_TYPE = 'nodeType';
// these are all "safe" returns, no wrapping required
Y.each([
/**
* Returns the inner width of the viewport (exludes scrollbar).
* @property winWidth
* @type {Int}
*/
'winWidth',
/**
* Returns the inner height of the viewport (exludes scrollbar).
* @property winHeight
* @type {Int}
*/
'winHeight',
/**
* Document width
* @property winHeight
* @type {Int}
*/
'docWidth',
/**
* Document height
* @property docHeight
* @type {Int}
*/
'docHeight',
/**
* Amount page has been scroll vertically
* @property docScrollX
* @type {Int}
*/
'docScrollX',
/**
* Amount page has been scroll horizontally
* @property docScrollY
* @type {Int}
*/
'docScrollY'
],
function(name) {
getter: function() {
}
};
}
);
getter: function() {
},
if (node) {
if ('scrollLeft' in node) {
}
} else {
}
}
};
getter: function() {
},
if (node) {
if ('scrollTop' in node) {
}
} else {
}
}
};
/**
* Gets the current position of the node in page coordinates.
* Nodes must be part of the DOM tree to have page coordinates
* (display:none or nodes not appended return false).
* @method getXY
* @return {Array} The XY position of the node
*/
'getXY',
/**
* Set the position of the node in page coordinates, regardless of how the node is positioned.
* The node must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @method setXY
* @param {Array} xy Contains X & Y values for new position (coordinates are page-based)
* @chainable
*/
'setXY',
/**
* Gets the current position of the node in page coordinates.
* Nodes must be part of the DOM tree to have page coordinates
* (display:none or nodes not appended return false).
* @method getX
* @return {Int} The X position of the node
*/
'getX',
/**
* Set the position of the node in page coordinates, regardless of how the node is positioned.
* The node must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @method setX
* @param {Int} x X value for new position (coordinates are page-based)
* @chainable
*/
'setX',
/**
* Gets the current position of the node in page coordinates.
* Nodes must be part of the DOM tree to have page coordinates
* (display:none or nodes not appended return false).
* @method getY
* @return {Int} The Y position of the node
*/
'getY',
/**
* Set the position of the node in page coordinates, regardless of how the node is positioned.
* The node must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @method setY
* @param {Int} y Y value for new position (coordinates are page-based)
* @chainable
*/
'setY'
]);
/**
* Extended Node interface for managing regions and screen positioning.
* Adds support for positioning elements and normalizes window size and scroll detection.
* @module node
* @submodule node-screen
* @for Node
*/
/**
* Returns a region object for the node
* @property region
* @type Node
*/
getter: function() {
}
}
}
};
/**
* Returns a region object for the node's viewport
* @property viewportRegion
* @type Node
*/
getter: function() {
}
};
// these need special treatment to extract 2nd node arg
/**
* Compares the intersection of the node with another node or region
* @method intersect
* @param {Node|Object} node2 The node or region to compare with.
* @param {Object} altRegion An alternate region to use (rather than this node's).
* @return {Object} An object representing the intersection of the regions.
*/
}
};
/**
* Determines whether or not the node is within the giving region.
* @method inRegion
* @param {Node|Object} node2 The node or region to compare with.
* @param {Boolean} all Whether or not all of the node must be in the region.
* @param {Object} altRegion An alternate region to use (rather than this node's).
* @return {Object} An object representing the intersection of the regions.
*/
}
};
getter: function() {
},
return val;
}
});
} else {
}
};
YUI.add('node', function(Y){}, '@VERSION@' ,{use:['node-base', 'node-style', 'node-screen', 'node-aria'], skinnable:false});