node.js revision f632d630e3fee201f37c3ffdafc3e00801245058
/**
* 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
};
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;
};
if (val) { // only truthy values are risky
{
val = null; // not allowed to go outside of root node
} else {
} else { // assume nodeList
}
}
} 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]) {
}
}
}
}
},
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() {
return Node.DEFAULT_GETTER.call(this, attr);
},
*/
}
});
} else {
}
},
},
}
},
/**
* 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
*/
},
//if (!this.attrAdded(attr)) {
//this._addAttr(attr);
}
},
this._addDOMAttr(attr);
} else { // handle chained properties TODO: can Attribute do this? Not sure we want events
}
}
},
/**
* 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.
*/
},
// TODO: safe enough?
ret;
if (a && a instanceof Y.Node) { // first 2 may be Node instances
a = Node.getDOMNode(a);
}
if (b && b instanceof Y.Node) { // first 2 may be Node instances
b = Node.getDOMNode(b);
}
},
destructor: function() {
},
/**
* 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? check for fn; document this
}
}, true);