node.js revision 0e38c4f630dc17d5d1966f48feff30dc4de42c78
/**
* 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
* @for Node
*/
// "globals"
var DOT = '.',
NODE_NAME = 'nodeName',
NODE_TYPE = 'nodeType',
OWNER_DOCUMENT = 'ownerDocument',
TAG_NAME = 'tagName',
UID = '_yuid',
}
if (!uid) { // stamp failed; likely IE non-HTMLElement
}
if (this._initPlugins) { // when augmented with Plugin.Host
this._initPlugins();
}
},
var ret = null;
if (fn) {
function(n) {
} :
function(n) {
};
}
return ret;
};
// end "globals"
Node.DOM_EVENTS = {
abort: true,
beforeunload: 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,
message: 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._instances = {};
/**
* Retrieves the DOM node bound to a Node instance
* @method Node.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) {
}
return null;
};
}
}
}
return val;
};
ret;
}
}
return ret;
};
} else {
}
};
if (typeof name === 'string') {
} else {
});
}
};
/**
* Returns a single Node instance bound to the node or the
* first element matching the given selector.
* @method Y.one
* @static
* @param {String | HTMLElement} node a node or Selector
* @param {Y.Node || HTMLElement} doc an optional document to scan. Defaults to Y.config.doc.
*/
var instance = null,
uid;
if (node) {
if (typeof node === 'string') {
} else {
}
if (!node) {
return null;
}
return node; // NOTE: return
}
}
}
return instance;
};
/**
* Returns a single Node instance bound to the node or the
* first element matching the given selector.
* @method Y.get
* @deprecated Use Y.one
* @static
* @param {String | HTMLElement} node a node or Selector
* @param {Y.Node || HTMLElement} doc an optional document to scan. Defaults to Y.config.doc.
*/
};
/**
* Creates a new dom node using the provided markup string.
* @method create
* @static
* @param {String} html The markup used to create the element
* @param {HTMLDocument} doc An optional document context
*/
};
/**
* Allows for getting and setting the text of an element.
* Formatting is preserved and special characters are treated literally.
* @config text
* @type String
*/
text: {
getter: function() {
},
return content;
}
},
'options': {
getter: function() {
}
},
// IE: elements collection is also FORM node which trips up scrubVal.
// preconverting to NodeList
// TODO: break out for IE only
'elements': {
getter: function() {
}
},
/**
* Returns a NodeList instance of all HTMLElement children.
* @readOnly
* @config children
* @type NodeList
*/
'children': {
getter: function() {
childNodes, i, len;
if (!children) {
children = [];
if (childNodes[i][TAG_NAME]) {
}
}
}
return children;
}
},
value: {
getter: function() {
},
return val;
}
},
data: {
getter: function() {
return this._data;
},
return val;
}
}
};
// call with instance context
var node = this._stateProxy,
// only allow when defined on node
}
return val;
};
// call with instance context
var node = this._stateProxy,
val;
}
return val;
};
toString: function() {
var str = '',
if (node) {
}
}
// TODO: add yuid?
}
},
/**
* Returns an attribute value on the Node instance
* @method get
* @param {String} attr The attribute to be set
* @return {any} The current value of the attribute
*/
var val;
if (this._getAttr) { // use Attribute imple
} else {
}
if (val) {
}
return val;
},
val;
} else {
}
return val;
},
/**
* Sets an attribute on the Node instance.
* @method set
* @param {String} attr The attribute to be set.
* @param {any} val The value to set the attribute to.
* @chainable
*/
if (this._setAttr) { // use Attribute imple
} else { // use setters inline
} else {
}
}
return this;
},
/**
* Sets multiple attributes.
* @method setAttrs
* @chainable
*/
if (this._setAttrs) { // use Attribute imple
} else { // use setters inline
this.set(n, v);
}, this);
}
return this;
},
/**
* Returns an object containing the values for the requested attributes.
* @method getAttrs
* @param {Array} attrs an array of attributes to get values
*/
var ret = {};
if (this._getAttrs) { // use Attribute imple
} else { // use setters inline
}, this);
}
return ret;
},
/**
* Creates a new 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
*/
/**
* 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 string 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.
* @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.
* @return {Node} Node instance or null if not found
*/
},
/**
* Retrieves a Node instance of nodes based on the given CSS selector.
* @method one
*
* @param {string} selector The CSS selector to test against.
* @return {Node} A Node instance for the matching HTMLElement.
*/
},
/**
* Retrieves a Node instance of nodes based on the given CSS selector.
* @method query
* @deprecated Use one()
* @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 all
*
* @param {string} selector The CSS selector to test against.
* @return {NodeList} A NodeList instance for the matching HTMLCollection/Array.
*/
},
/**
* Retrieves a nodeList based on the given CSS selector.
* @method queryAll
* @deprecated Use all()
* @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
*
*/
if (destroy) {
this.destroy(true);
}
return this;
},
/**
* Replace the node with the other node. This is a DOM update only
* and does not change the node bound to the Node instance.
* Shortcut for myNode.get('parentNode').replaceChild(newNode, myNode);
* @method replace
* @chainable
*
*/
return this;
},
},
if (purge) {
this.purge(true);
}
if (this.unplug) {
this.unplug();
}
this._node = null;
this._stateProxy = null;
},
/**
* Invokes a method on the Node instance
* @method invoke
* @param {String} method The name of the method to invoke
* @param {Any} a, b, c, etc. Arguments to invoke the method with.
* @return Whatever the underly method returns.
* DOM Nodes and Collections return values
*
*/
ret;
if (a && a instanceof Y.Node) {
a = a._node;
}
if (b && b instanceof Y.Node) {
b = b._node;
}
},
/**
* 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
* @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.
* @chainable
*/
if (content) {
}
});
return this; // NOTE: early return
}
}
}
return this;
},
/**
* Inserts the content as the firstChild of the node.
* @method prepend
* @param {String | Y.Node | HTMLElement} content The content to insert
* @chainable
*/
},
/**
* Inserts the content as the lastChild of the node.
* @method append
* @param {String | Y.Node | HTMLElement} content The content to insert
* @chainable
*/
},
/**
* Replaces the node's current content with the content.
* @method setContent
* @param {String | Y.Node | HTMLElement} content The content to insert
* @chainable
*/
setContent: function(content) {
return this;
},
// TODO: need this?
}
}, true);