node-base-debug.js revision 6469c0fd34f5d65f53cc4c8097c46e732a0819ae
c544ac2705cf516901c8455356d56b52c8615525mfloryan * The Node Utility provides a DOM-like interface for interacting with DOM nodes.
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @module node
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @submodule node-base
c544ac2705cf516901c8455356d56b52c8615525mfloryan * The Node class provides a wrapper for manipulating DOM Nodes.
c544ac2705cf516901c8455356d56b52c8615525mfloryan * Node properties can be accessed via the set/get methods.
c544ac2705cf516901c8455356d56b52c8615525mfloryan * Use Y.get() to retrieve Node instances.
c544ac2705cf516901c8455356d56b52c8615525mfloryan * <strong>NOTE:</strong> Node properties are accessed using
c544ac2705cf516901c8455356d56b52c8615525mfloryan * the <code>set</code> and <code>get</code> methods.
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @class Node
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @constructor
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @for Node
c544ac2705cf516901c8455356d56b52c8615525mfloryan// "globals"
c544ac2705cf516901c8455356d56b52c8615525mfloryan if (uid && Node._instances[uid] && Node._instances[uid]._node !== node) {
c544ac2705cf516901c8455356d56b52c8615525mfloryan node[UID] = null; // unset existing uid to prevent collision (via clone or hack)
c544ac2705cf516901c8455356d56b52c8615525mfloryan if (!uid) { // stamp failed; likely IE non-HTMLElement
c544ac2705cf516901c8455356d56b52c8615525mfloryan this._stateProxy = node; // when augmented with Attribute
c544ac2705cf516901c8455356d56b52c8615525mfloryan if (this._initPlugins) { // when augmented with Plugin.Host
c544ac2705cf516901c8455356d56b52c8615525mfloryan // used with previous/next/ancestor tests
c544ac2705cf516901c8455356d56b52c8615525mfloryan var ret = null;
c544ac2705cf516901c8455356d56b52c8615525mfloryan function(n) {
c544ac2705cf516901c8455356d56b52c8615525mfloryan function(n) {
c544ac2705cf516901c8455356d56b52c8615525mfloryan// end "globals"
c544ac2705cf516901c8455356d56b52c8615525mfloryan// Add custom event adaptors to this list. This will make it so
c544ac2705cf516901c8455356d56b52c8615525mfloryan// that delegate, key, available, contentready, etc all will
c544ac2705cf516901c8455356d56b52c8615525mfloryan// be available through Node.on
c544ac2705cf516901c8455356d56b52c8615525mfloryan * Retrieves the DOM node bound to a Node instance
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @method Node.getDOMNode
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @param {Y.Node || HTMLNode} node The Node instance or an HTMLNode
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @return {HTMLNode} The DOM node bound to the Node instance. If a DOM node is passed
c544ac2705cf516901c8455356d56b52c8615525mfloryan * as the node argument, it is simply returned.
c544ac2705cf516901c8455356d56b52c8615525mfloryan return (node.nodeType) ? node : node._node || null;
c544ac2705cf516901c8455356d56b52c8615525mfloryan return null;
c544ac2705cf516901c8455356d56b52c8615525mfloryan if (typeof val === 'object' || typeof val === 'function') { // safari nodeList === function
c544ac2705cf516901c8455356d56b52c8615525mfloryan if (NODE_TYPE in val || Y.DOM.isWindow(val)) {// node || window
c544ac2705cf516901c8455356d56b52c8615525mfloryan } else if ((val.item && !val._nodes) || // dom collection or Node instance
c544ac2705cf516901c8455356d56b52c8615525mfloryan (val[0] && val[0][NODE_TYPE])) { // array of DOM Nodes
c544ac2705cf516901c8455356d56b52c8615525mfloryan ret = Node.scrubVal(fn.apply(context, args), this);
c544ac2705cf516901c8455356d56b52c8615525mfloryan Y.log('unable to add method: ' + name, 'warn', 'Node');
c544ac2705cf516901c8455356d56b52c8615525mfloryan * Returns a single Node instance bound to the node or the
c544ac2705cf516901c8455356d56b52c8615525mfloryan * first element matching the given selector.
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @method Y.one
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @param {String | HTMLElement} node a node or Selector
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @param {Y.Node || HTMLElement} doc an optional document to scan. Defaults to Y.config.doc.
c544ac2705cf516901c8455356d56b52c8615525mfloryan if (node.indexOf('doc') === 0) { // doc OR document
c544ac2705cf516901c8455356d56b52c8615525mfloryan } else if (node.indexOf('win') === 0) { // win OR window
c544ac2705cf516901c8455356d56b52c8615525mfloryan return null;
c544ac2705cf516901c8455356d56b52c8615525mfloryan instance = Node._instances[uid]; // reuse exising instances
c544ac2705cf516901c8455356d56b52c8615525mfloryan if (!instance || (cachedNode && node !== cachedNode)) { // new Node when nodes don't match
c544ac2705cf516901c8455356d56b52c8615525mfloryan * Returns a single Node instance bound to the node or the
c544ac2705cf516901c8455356d56b52c8615525mfloryan * first element matching the given selector.
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @method Y.get
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @deprecated Use Y.one
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @param {String | HTMLElement} node a node or Selector
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @param {Y.Node || HTMLElement} doc an optional document to scan. Defaults to Y.config.doc.
c544ac2705cf516901c8455356d56b52c8615525mfloryan Y.log('Y.get is deprecated, use Y.one', 'warn', 'deprecated');
c544ac2705cf516901c8455356d56b52c8615525mfloryan * Creates a new dom node using the provided markup string.
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @method create
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @param {String} html The markup used to create the element
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @param {HTMLDocument} doc An optional document context
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @return {Node} A Node instance bound to a DOM node or fragment
c544ac2705cf516901c8455356d56b52c8615525mfloryan return Y.one(Y.DOM.create.apply(Y.DOM, arguments));
c544ac2705cf516901c8455356d56b52c8615525mfloryan * Allows for getting and setting the text of an element.
c544ac2705cf516901c8455356d56b52c8615525mfloryan * Formatting is preserved and special characters are treated literally.
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @config text
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @type String
c544ac2705cf516901c8455356d56b52c8615525mfloryan getter: function() {
c544ac2705cf516901c8455356d56b52c8615525mfloryan 'options': {
c544ac2705cf516901c8455356d56b52c8615525mfloryan getter: function() {
c544ac2705cf516901c8455356d56b52c8615525mfloryan // IE: elements collection is also FORM node which trips up scrubVal.
c544ac2705cf516901c8455356d56b52c8615525mfloryan // preconverting to NodeList
c544ac2705cf516901c8455356d56b52c8615525mfloryan // TODO: break out for IE only
c544ac2705cf516901c8455356d56b52c8615525mfloryan 'elements': {
c544ac2705cf516901c8455356d56b52c8615525mfloryan getter: function() {
c544ac2705cf516901c8455356d56b52c8615525mfloryan * Returns a NodeList instance of all HTMLElement children.
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @readOnly
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @config children
c544ac2705cf516901c8455356d56b52c8615525mfloryan * @type NodeList
c544ac2705cf516901c8455356d56b52c8615525mfloryan 'children': {
c544ac2705cf516901c8455356d56b52c8615525mfloryan getter: function() {
c544ac2705cf516901c8455356d56b52c8615525mfloryan for (i = 0, len = childNodes.length; i < len; ++i) {
c544ac2705cf516901c8455356d56b52c8615525mfloryan getter: function() {
c544ac2705cf516901c8455356d56b52c8615525mfloryan getter: function() {
c544ac2705cf516901c8455356d56b52c8615525mfloryan return this._data;
c544ac2705cf516901c8455356d56b52c8615525mfloryan// call with instance context
c544ac2705cf516901c8455356d56b52c8615525mfloryan // only allow when defined on node
c544ac2705cf516901c8455356d56b52c8615525mfloryan } else if (node[name] !== undefined) { // pass thru DOM properties
c544ac2705cf516901c8455356d56b52c8615525mfloryan// call with instance context
c544ac2705cf516901c8455356d56b52c8615525mfloryan } else if (node[name] !== undefined) { // pass thru from DOM
c544ac2705cf516901c8455356d56b52c8615525mfloryan toString: function() {
var val;
if (val) {
return val;
val;
return val;
this.set(n, v);
var ret = {};
return ret;
ret = null;
return ret;
* @return {NodeList} A NodeList instance for the matching HTMLCollection/Array.
return nodelist;
* @return {NodeList} A NodeList instance for the matching HTMLCollection/Array.
if (parentNode) {
if (destroy) {
this.destroy(true);
this.unplug();
this._node = null;
this._stateProxy = null;
ret;
if (a && a instanceof Y.Node) {
a = a._node;
if (b && b instanceof Y.Node) {
b = b._node;
size: function() {
if (content) {
if (content) {
function(otherNode) {
function(otherNode) {
var ret = [],
ctx,
if (!instance) {
if (!tmp) {
return tmp;
var instance = this;
return instance;
var nodelist = this;
if (!instance) {
return nodelist;
var instance = this;
toFrag: function() {
modulus: function(n, r) {
var nodes = [];
odd: function() {
even: function() {
destructor: function() {
refresh: function() {
var doc,
if (query) {
if (!root) {
size: function() {
isEmpty: function() {
toString: function() {
node;
var ret = [],
isNodeList = false,
val;
isNodeList = true;
if (!instance) {
Y.Array.each([
], function(method) {
return ret;
var methods = [
return val;
getter: function() {