node.js revision 5a649ae46349374f97b2a45de1dcd3fa6c03513b
/**
* The Node Utility provides a DOM-like interface for interacting with DOM nodes.
* @module node
* @submodule node-base
*/
/**
* The Node class provides a wrapper for manipulating DOM Nodes.
* Use Y.get() to retrieve Node instances.
*
* <strong>NOTE:</strong> Node properties are accessed using
* the <code>set</code> and <code>get</code> methods.
*
* @class Node
* @constructor
*/
var OWNER_DOCUMENT = 'ownerDocument',
TAG_NAME = 'tagName',
NODE_NAME = 'nodeName',
NODE_TYPE = 'nodeType',
_instances = {},
_restrict = {},
var ret = null;
if (fn) {
function(n) {
} :
function(n) {
};
}
return ret;
};
if (node) {
} else {
}
}
}
return doc;
};
var _getDOMNode = function(node) {
}
return node || null;
};
var Node = function() {
};
/**
* @property PLUGINS
* Registry for statically configured plugins.
* Default plugins added to all Node instances.
* @static
* Plugins are registered as objects with "fn" and "cfg" fields:
* Y.Node.PLUGINS.push({ fn: Y.plugin.NodeFX, cfg: {easing: 'easeOut'} });
*/
/**
* @method Node.plug
* Add a default plugin to be plugged into all instances.
* @static
* @param {Function || String} p The plugin class. String assumes Y.plugin[p]
* @param {Object} config A default plugin configuration applied to all instances.
*
*/
};
i;
if (pl > 0) {
}
}
return val;
};
i,
o;
if (leafIdx >= 0) {
o = val;
o = o[path[i]];
}
}
}
};
if (val !== null && (
) {
val = null; // not allowed to go outside of root node
} else {
} else {
}
}
} else {
if (depth > 0) {
for (var i in val) { // TODO: test this and pull hasOwnProperty check if safe?
}
}
}
}
}
} else {
}
return val;
};
/**
* Normalizes nodeInnerText and textContent.
* @property text
* @type String
*/
'text': function(node) {
},
'options': function(node) {
},
/**
* Returns a NodeList instance.
* @property children
* @type NodeList
*/
'children': function(node) {
children = [];
if (childNodes[i][TAG_NAME]) {
}
}
}
return children;
}
};
if (typeof name == 'string') {
instance = this,
val;
if (getAll) {
} else {
}
};
return ret;
};
} else { // assume object
});
}
};
/**
* @method getDOMNode
* @static
* @param node A Node instance
* @return DOMNode The DOM node bound to the Node instance
*/
return function() {
};
};
// rename and mark as protected
var add = {};
});
};
var uid;
this.getId = function() {
return uid;
};
if (fn) {
i = i || 0;
}
}
return nodes;
};
// uid = selector || Y.guid(); // to cache queryAll results
if (nodes) { // zero length collection returns null
}
} else {
nodes = [];
}
try { // IE only allows ID on Element
}
} catch(e) { // not cacheable
}
}
if (!getAll) {
_instances[uid] = this;
}
this._initPlugins();
},
_initPlugins: function(config) {
}
},
/**
* 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
*/
},
/**
* 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
*/
});
},
/**
* Returns the current number of items in the NodeList.
* @method size
* @return {Int} The number of items in the NodeList.
*/
size: function() {
},
/**
* 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.
*/
},
/**
* Attaches a DOM event handler.
* @method attach
* @param {String} type The type of DOM Event to listen for
* @param {Function} fn The handler to call when the event fires
* @param {Object} arg An argument object to pass to the handler
*/
},
/**
* Alias for attach.
* @method on
* @param {String} type The type of DOM Event to listen for
* @param {Function} fn The handler to call when the event fires
* @param {Object} arg An argument object to pass to the handler
* @see attach
*/
},
/**
* 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
*/
},
/**
* Creates a Node instance from HTML string
* @method create
* @param {String|Array} html The string of html to create
* @return {Node} A new Node instance
*/
},
/**
* Applies the supplied plugin to the node.
* @method plug
* @param {Function} The plugin Class to apply
* @param {Object} config An optional config to pass to the constructor
* @chainable
*/
if (p) {
if (typeof p === 'string' && Y.plugin) {
} else if (p.fn) {
} else if (Y.Lang.isFunction(p)) {
} else {
this.plug(p[i]);
}
}
}
return this;
},
// TODO: configurable plugin nodeType?
} else {
this[ns] = null;
}
}
},
//normalize: function() {},
//isSupported: function(feature, version) {},
toString: function() {
if (nodes) {
}
}
}
}
}
};
addEventListener: function() {
},
removeEventListener: function() {
},
/**
* @method set
* @param {String} prop Property to set
* @param {any} val Value to apply to the given property
* @chainable
*/
// TODO: document.location.href
// TODO: blacklist?
} else {
}
} else {
}
},
/**
* @method get
* @param {String} prop Property to get
* @return {any} Current value of the property
*/
// TODO: blacklist?
var val = null;
if (prop) {
} else {
}
// method wrapper uses undefined in chaining test
val = null;
}
} else {
}
}
return val;
},
// TODO: safe enough?
var ret;
if (a) { // first 2 may be Node instances
a = (a[NODE_TYPE]) ? a : _getDOMNode(a);
if (b) {
b = (b[NODE_TYPE]) ? b : _getDOMNode(b);
}
}
return ret;
},
// TODO: need this? check for fn; document this
},
/**
* 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.
*/
if (!ret) {
ret = null;
}
return ret;
},
/**
* Retrieves a nodeList based on the given CSS selector.
* @method queryAll
* @deprecated Use query() which returns all matches
*
* @param {string} selector The CSS selector to test against.
* @return {NodeList} A NodeList instance for the matching HTMLCollection/Array.
*/
ret = null;
}
return ret;
},
// 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.
*/
},
/**
* 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.
*/
},
/**
* 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
*/
},
/**
* Determines whether the ndoe is an ancestor of another HTML element in the DOM hierarchy.
* @method contains
* @param {Node | HTMLElement} needle The possible node or descendent
* @return {Boolean} Whether or not this node is the needle its ancestor
*/
},
/**
* 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) {
}
},
ret = null;
}
return ret;
}
});
/**
* Creates a Node instance from an HTML string
* @method create
* @param {String} html HTML string
*/
};
};
/**
* Retrieves a Node instance for the given query or nodes.
* Note: Use 'document' string to retrieve document Node instance from string
* @method Y.get
* @static
* @param {document|HTMLElement|HTMLCollection|Array|String} node The object to wrap.
* @param {document|Node} doc optional The document containing the node. Defaults to current document.
* @param {boolean} isRoot optional Whether or not this node should be treated as a root node. Root nodes
* aren't allowed to traverse outside their DOM tree.
* @return {Node} A Node instance bound to the supplied node(s).
*/
// TODO: check restricted return
// rename isRoot to restricted
var instance;
return node;
} else if (typeof node === 'string') {
}
if (node) {
if (!getAll) { // reuse single element node instances
// verify IE's uniqueID in case the node was cloned
}
}
}
if (!instance) {
}
}
}
// zero length collection returns null
};
var node;
} else {
}
return node;
};
/**
* @method Y.all
* @static
* @param {HTMLCollection|Array|String} node The object to wrap.
* @param {document|Node} doc optional The document containing the node. Defaults to current document.
* @param {boolean} isRoot optional Whether or not this node should be treated as a root node. Root nodes
* @return {NodeList} A NodeList instance for the supplied nodes.
*/
};
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 getAttribute
* @param {String} attribute The attribute to retrieve
* @return {String} The current value of the attribute
*/
'getAttribute',
/**
* Passes through to DOM method.
* @method setAttribute
* @param {String} attribute The attribute to set
* @param {String} The value to apply to the attribute
* @chainable
*/
'setAttribute',
/**
* 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;
};
});
// TODO: falsey empty string val? foo in attributes?
}
});
}
// used to call Node methods against NodeList nodes