node.js revision 8a46939c7ec2e3a8af3fd8ee4c8ef30d60e019a2
/**
* 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 Node
* @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,
var config = null;
if (!this[UID]) { // stamp failed; likely IE non-HTMLElement
}
if (restricted) {
config = {
};
g_restrict[this[UID]] = true;
}
this._lazyAttrInit = true;
this._silentInit = true;
},
var ret = null;
if (fn) {
function(n) {
} :
function(n) {
};
}
return ret;
};
// end "globals"
Node.DOM_EVENTS = {
abort: true,
blur: true,
change: true,
click: true,
close: true,
command: true,
contextmenu: true,
drag: true,
dragstart: true,
dragenter: true,
dragover: true,
dragleave: true,
dragend: true,
drop: true,
dblclick: true,
error: true,
focus: true,
keydown: true,
keypress: true,
keyup: true,
load: true,
mousedown: true,
mousemove: true,
mouseout: true,
mouseover: true,
mouseup: true,
mousemultiwheel: true,
mousewheel: true,
submit: true,
mouseenter: true,
mouseleave: true,
scroll: true,
reset: true,
resize: true,
select: true,
textInput: true,
unload: true
};
// Add custom event adaptors to this list. This will make it so
// that delegate, key, available, contentready, etc all will
// be available through Node.on
Node.EXEC_SCRIPTS = true;
Node._instances = {};
return Node;
};
return Node;
};
/**
* 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() {
},
}
},
/*
style: {
getter: function(attr) {
return Y.DOM.getStyle(g_nodes[this[UID]].style, attr);
}
},
*/
restricted: {
writeOnce: true,
value: false
}
};
// call with instance context
}
return this;
};
// call with instance context
val;
} else {
}
};
toString: function() {
var str = '',
if (node) {
}
}
// TODO: add yuid?
}
},
_addDOMAttr: function(attr) {
getter: function() {
},
}
});
} else {
}
},
this._addAriaAttr(attr);
} else {
}
}
},
// except for aria
this._addAriaAttr(attr);
// or chained properties or if no change listeners
this._addDOMAttr(attr);
} else {
return this; // NOTE: return
}
}
return this;
},
/**
* 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() {
//var uid = this[UID];
//delete g_nodes[uid];
//delete g_restrict[uid];
//delete Node._instances[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() {
},
/**
* Inserts the content before the reference node.
* @method insert
* @param {String | Y.Node | HTMLElement} content The content to insert
* @param {Int | Y.Node | HTMLElement | String} where The position to insert at.
* @param {Boolean} execScripts Whether or not to execute any scripts found in
* the content. If false, all scripts will be stripped out.
* @chainable
*/
//TODO: restrict
if (content) {
}
}
if (!where || // only allow inserting into this Node's subtree
(!g_restrict[this[UID]] ||
}
}
return this;
},
/**
* Inserts the content as the firstChild of the node.
* @method prepend
* @param {String | Y.Node | HTMLElement} content The content to insert
* @param {Boolean} execScripts Whether or not to execute any scripts found in
* the content. If false, all scripts will be stripped out.
* @chainable
*/
},
/**
* Inserts the content as the lastChild of the node.
* @method append
* @param {String | Y.Node | HTMLElement} content The content to insert
* @param {Boolean} execScripts Whether or not to execute any scripts found in
* the content. If false, all scripts will be stripped out.
* @chainable
*/
},
/**
* Replaces the node's current content with the content.
* @method setContent
* @param {String | Y.Node | HTMLElement} content The content to insert
* @param {Boolean} execScripts Whether or not to execute any scripts found in
* the content. If false, all scripts will be stripped out.
* @chainable
*/
return this;
},
// TODO: need this?
}
}, true);