node-base-debug.js revision 44d4f272b35aec28ecaacadf6bc6eb497fd509d3
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassYUI.add('node-base', function(Y) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove/**
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @module node
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @submodule node-base
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove */
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeneyvar methods = [
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Determines whether each node has the given className.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method hasClass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for Node
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} className the class name to search for
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @return {Boolean} Whether or not the element has the specified class
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'hasClass',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Adds a class name to each node.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @method addClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} className the class name to add to the node's class attribute
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'addClass',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney/**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Removes a class name from each node.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @method removeClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} className the class name to remove from the node's class attribute
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'removeClass',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Replace a class with another class for each node.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * If no oldClassName is present, the newClassName is simply added.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @method replaceClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} oldClassName the class name to be replaced
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} newClassName the class name that will be replacing the old class name
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'replaceClass',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * If the className exists on the node it is removed, if it doesn't exist it is added.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @method toggleClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} className the class name to be toggled
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {Boolean} force Option to force adding or removing the class.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'toggleClass'
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY.Node.importMethod(Y.DOM, methods);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Determines whether each node has the given className.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method hasClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.hasClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @for NodeList
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} className the class name to search for
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @return {Array} An array of booleans for each node bound to the NodeList.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Adds a class name to each node.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @method addClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.addClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} className the class name to add to the node's class attribute
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Removes a class name from each node.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @method removeClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.removeClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} className the class name to remove from the node's class attribute
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Replace a class with another class for each node.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * If no oldClassName is present, the newClassName is simply added.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @method replaceClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.replaceClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} oldClassName the class name to be replaced
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} newClassName the class name that will be replacing the old class name
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * If the className exists on the node it is removed, if it doesn't exist it is added.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @method toggleClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.toggleClass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} className the class name to be toggled
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY.NodeList.importMethod(Y.Node.prototype, methods);
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove/**
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @module node
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @submodule node-base
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove */
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeneyvar Y_Node = Y.Node,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney Y_DOM = Y.DOM;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Returns a new dom node using the provided markup string.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method create
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @static
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} html The markup used to create the element
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {HTMLDocument} doc An optional document context
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {Node} A Node instance bound to a DOM node or fragment
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @for Node
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassY_Node.create = function(html, doc) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (doc && doc._node) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass doc = doc._node;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Y.one(Y_DOM.create(html, doc));
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass};
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY.mix(Y_Node.prototype, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Creates a new Node using the provided markup string.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method create
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} html The markup used to create the element
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {HTMLDocument} doc An optional document context
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @return {Node} A Node instance bound to a DOM node or fragment
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney create: Y_Node.create,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Inserts the content before the reference node.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method insert
5770dec23508300b0e77edf1fd63b699b89e4615Luke Smith * @param {String | Node | HTMLElement | NodeList | HTMLCollection} content The content to insert
5770dec23508300b0e77edf1fd63b699b89e4615Luke Smith * @param {Int | Node | HTMLElement | String} where The position to insert at.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Possible "where" arguments
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dl>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dt>Y.Node</dt>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dd>The Node to insert before</dd>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dt>HTMLElement</dt>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dd>The element to insert before</dd>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dt>Int</dt>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dd>The index of the child element to insert before</dd>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dt>"replace"</dt>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dd>Replaces the existing HTML</dd>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dt>"before"</dt>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dd>Inserts before the existing HTML</dd>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dt>"before"</dt>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dd>Inserts content before the node</dd>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dt>"after"</dt>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * <dd>Inserts content after the node</dd>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * </dl>
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney insert: function(content, where) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney this._insert(content, where);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return this;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney _insert: function(content, where) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney var node = this._node,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney ret = null;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney if (typeof where == 'number') { // allow index
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney where = this._node.childNodes[where];
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney } else if (where && where._node) { // Node
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney where = where._node;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney if (content && typeof content != 'string') { // allow Node or NodeList/Array instances
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney content = content._node || content._nodes || content;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney ret = Y_DOM.addHTML(node, content, where);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return ret;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Inserts the content as the firstChild of the node.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method prepend
5770dec23508300b0e77edf1fd63b699b89e4615Luke Smith * @param {String | Node | HTMLElement} content The content to insert
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney prepend: function(content) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return this.insert(content, 0);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Inserts the content as the lastChild of the node.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method append
5770dec23508300b0e77edf1fd63b699b89e4615Luke Smith * @param {String | Node | HTMLElement} content The content to insert
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @chainable
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney append: function(content) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return this.insert(content, null);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method appendChild
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {String | HTMLElement | Node} node Node to be appended
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @return {Node} The appended node
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney appendChild: function(node) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return Y_Node.scrubVal(this._insert(node));
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method insertBefore
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {String | HTMLElement | Node} newNode Node to be appended
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {HTMLElement | Node} refNode Node to be inserted before
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @return {Node} The inserted node
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney insertBefore: function(newNode, refNode) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return Y.Node.scrubVal(this._insert(newNode, refNode));
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * Appends the node to the given node.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method appendTo
5770dec23508300b0e77edf1fd63b699b89e4615Luke Smith * @param {Node | HTMLElement} node The node to append to
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney appendTo: function(node) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney Y.one(node).append(this);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Replaces the node's current content with the content.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method setContent
5770dec23508300b0e77edf1fd63b699b89e4615Luke Smith * @param {String | Node | HTMLElement | NodeList | HTMLCollection} content The content to insert
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney setContent: function(content) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney this._insert(content, 'replace');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * Returns the node's current content (e.g. innerHTML)
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method getContent
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @return {String} The current content
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney getContent: function(content) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return this.get('innerHTML');
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney});
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt Sweeney/**
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt Sweeney * Replaces the node's current html content with the content provided.
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt Sweeney * @method setHTML
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt Sweeney * @param {String | HTML | Node | HTMLElement | NodeList | HTMLCollection} content The content to insert
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt Sweeney * @chainable
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt Sweeney */
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt SweeneyY.Node.prototype.setHTML = Y.Node.prototype.setContent;
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt Sweeney
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt Sweeney/**
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt Sweeney * Returns the node's current html content (e.g. innerHTML)
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt Sweeney * @method getContent
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt Sweeney * @return {String} The html content
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt Sweeney */
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt SweeneyY.Node.prototype.getHTML = Y.Node.prototype.getContent;
2895ebd7cac94f09e29d6fc2b4aa601ca686cbe6Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY.NodeList.importMethod(Y.Node.prototype, [
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Called on each Node instance
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @for NodeList
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method append
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.append
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'append',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney /** Called on each Node instance
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method insert
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.insert
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'insert',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Called on each Node instance
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @for NodeList
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method appendChild
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.appendChild
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'appendChild',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney /** Called on each Node instance
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method insertBefore
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.insertBefore
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'insertBefore',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney /** Called on each Node instance
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method prepend
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.prepend
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'prepend',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney /** Called on each Node instance
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method setContent
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.setContent
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'setContent',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney /** Called on each Node instance
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method getContent
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.getContent
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'getContent'
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney]);
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove/**
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @module node
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @submodule node-base
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove */
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeneyvar Y_Node = Y.Node,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney Y_DOM = Y.DOM;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney/**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Static collection of configuration attributes for special handling
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @property ATTRS
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @static
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @type object
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY_Node.ATTRS = {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Allows for getting and setting the text of an element.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Formatting is preserved and special characters are treated literally.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @config text
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @type String
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney text: {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney getter: function() {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return Y_DOM.getText(this._node);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney setter: function(content) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney Y_DOM.setText(this._node, content);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return content;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Allows for getting and setting the text of an element.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Formatting is preserved and special characters are treated literally.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @config for
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @type String
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'for': {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney getter: function() {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return Y_DOM.getAttribute(this._node, 'for');
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney setter: function(val) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney Y_DOM.setAttribute(this._node, 'for', val);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return val;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'options': {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney getter: function() {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return this._node.getElementsByTagName('option');
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Returns a NodeList instance of all HTMLElement children.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @readOnly
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @config children
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @type NodeList
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'children': {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney getter: function() {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney var node = this._node,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney children = node.children,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney childNodes, i, len;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney if (!children) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney childNodes = node.childNodes;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney children = [];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney for (i = 0, len = childNodes.length; i < len; ++i) {
17eee7fe7a558b9bd4e7e07e9d4f30bf530cae62Matt Sweeney if (childNodes[i].tagName) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney children[children.length] = childNodes[i];
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return Y.all(children);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney value: {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney getter: function() {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return Y_DOM.getValue(this._node);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney setter: function(val) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney Y_DOM.setValue(this._node, val);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return val;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney};
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY.Node.importMethod(Y.DOM, [
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Allows setting attributes on DOM nodes, normalizing in some cases.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * This passes through to the DOM node, allowing for custom attributes.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method setAttribute
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @for Node
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @for NodeList
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @chainable
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {string} name The attribute name
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {string} value The value to set
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'setAttribute',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Allows getting attributes on DOM nodes, normalizing in some cases.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * This passes through to the DOM node, allowing for custom attributes.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method getAttribute
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @for Node
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @for NodeList
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {string} name The attribute name
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @return {string} The attribute value
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'getAttribute'
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney]);
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove/**
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @module node
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @submodule node-base
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove */
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeneyvar Y_Node = Y.Node;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeneyvar Y_NodeList = Y.NodeList;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass/**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * List of events that route to DOM events
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @static
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @property DOM_EVENTS
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @for Node
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY_Node.DOM_EVENTS = {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney abort: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney beforeunload: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney blur: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney change: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney click: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney close: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney command: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney contextmenu: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney dblclick: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney DOMMouseScroll: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney drag: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney dragstart: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney dragenter: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney dragover: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney dragleave: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney dragend: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney drop: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney error: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney focus: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney key: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney keydown: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney keypress: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney keyup: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney load: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney message: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney mousedown: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney mouseenter: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney mouseleave: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney mousemove: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney mousemultiwheel: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney mouseout: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney mouseover: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney mouseup: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney mousewheel: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney orientationchange: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney reset: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney resize: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney select: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney selectstart: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney submit: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney scroll: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney textInput: 1,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney unload: 1
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney};
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney// Add custom event adaptors to this list. This will make it so
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney// that delegate, key, available, contentready, etc all will
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney// be available through Node.on
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY.mix(Y_Node.DOM_EVENTS, Y.Env.evt.plugins);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY.augment(Y_Node, Y.EventTarget);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY.mix(Y_Node.prototype, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Removes event listeners from the node and (optionally) its subtree
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method purge
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {Boolean} recurse (optional) Whether or not to remove listeners from the
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * node's subtree
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} type (optional) Only remove listeners of the specified type
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @chainable
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney *
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney purge: function(recurse, type) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney Y.Event.purgeElement(this._node, recurse, type);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney});
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY.mix(Y.NodeList.prototype, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _prepEvtArgs: function(type, fn, context) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // map to Y.on/after signature (type, fn, nodes, context, arg1, arg2, etc)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var args = Y.Array(arguments, 0, true);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (args.length < 2) { // type only (event hash) just add nodes
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass args[2] = this._nodes;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass args.splice(2, 0, this._nodes);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass args[3] = context || this; // default to NodeList instance as context
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return args;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith Subscribe a callback function for each `Node` in the collection to execute
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith in response to a DOM event.
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith NOTE: Generally, the `on()` method should be avoided on `NodeLists`, in
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith favor of using event delegation from a parent Node. See the Event user
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith guide for details.
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith Most DOM events are associated with a preventable default behavior, such as
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith link clicks navigating to a new page. Callbacks are passed a
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith `DOMEventFacade` object as their first argument (usually called `e`) that
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith can be used to prevent this default behavior with `e.preventDefault()`. See
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith the `DOMEventFacade` API for all available properties and methods on the
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith object.
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith By default, the `this` object will be the `NodeList` that the subscription
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith came from, <em>not the `Node` that received the event</em>. Use
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith `e.currentTarget` to refer to the `Node`.
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith Returning `false` from a callback is supported as an alternative to calling
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith `e.preventDefault(); e.stopPropagation();`. However, it is recommended to
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith use the event methods.
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith @example
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith Y.all(".sku").on("keydown", function (e) {
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith if (e.keyCode === 13) {
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith e.preventDefault();
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith // Use e.currentTarget to refer to the individual Node
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith var item = Y.MyApp.searchInventory( e.currentTarget.get('value') );
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith // etc ...
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith }
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith });
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith @method on
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith @param {String} type The name of the event
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith @param {Function} fn The callback to execute in response to the event
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith @param {Object} [context] Override `this` object in callback
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith @param {Any} [arg*] 0..n additional arguments to supply to the subscriber
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith @return {EventHandle} A subscription handle capable of detaching that
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith subscription
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith @for NodeList
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith **/
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney on: function(type, fn, context) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return Y.on.apply(Y, this._prepEvtArgs.apply(this, arguments));
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Applies an one-time event listener to each Node bound to the NodeList.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method once
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} type The event being listened for
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {Function} fn The handler to call when the event fires
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {Object} context The context to call the handler with.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Default is the NodeList instance.
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith * @return {EventHandle} A subscription handle capable of detaching that
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith * subscription
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith * @for NodeList
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney once: function(type, fn, context) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return Y.once.apply(Y, this._prepEvtArgs.apply(this, arguments));
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Applies an event listener to each Node bound to the NodeList.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * The handler is called only after all on() handlers are called
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * and the event is not prevented.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method after
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {String} type The event being listened for
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {Function} fn The handler to call when the event fires
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @param {Object} context The context to call the handler with.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Default is the NodeList instance.
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith * @return {EventHandle} A subscription handle capable of detaching that
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith * subscription
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith * @for NodeList
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney after: function(type, fn, context) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return Y.after.apply(Y, this._prepEvtArgs.apply(this, arguments));
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith },
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith /**
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith * Applies an one-time event listener to each Node bound to the NodeList
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith * that will be called only after all on() handlers are called and the
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith * event is not prevented.
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith *
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith * @method onceAfter
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith * @param {String} type The event being listened for
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith * @param {Function} fn The handler to call when the event fires
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith * @param {Object} context The context to call the handler with.
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith * Default is the NodeList instance.
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith * @return {EventHandle} A subscription handle capable of detaching that
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith * subscription
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith * @for NodeList
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith */
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith onceAfter: function(type, fn, context) {
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith return Y.onceAfter.apply(Y, this._prepEvtArgs.apply(this, arguments));
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney});
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY_NodeList.importMethod(Y.Node.prototype, [
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Called on each Node instance
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method detach
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.detach
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith * @for NodeList
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'detach',
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney /** Called on each Node instance
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method detachAll
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.detachAll
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith * @for NodeList
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'detachAll'
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass]);
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith/**
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke SmithSubscribe a callback function to execute in response to a DOM event or custom
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smithevent.
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke SmithMost DOM events are associated with a preventable default behavior such as
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smithlink clicks navigating to a new page. Callbacks are passed a `DOMEventFacade`
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smithobject as their first argument (usually called `e`) that can be used to
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smithprevent this default behavior with `e.preventDefault()`. See the
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith`DOMEventFacade` API for all available properties and methods on the object.
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke SmithIf the event name passed as the first parameter is not a whitelisted DOM event,
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smithit will be treated as a custom event subscriptions, allowing
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith`node.fire('customEventName')` later in the code. Refer to the Event user guide
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smithfor the full DOM event whitelist.
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke SmithBy default, the `this` object in the callback will refer to the subscribed
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith`Node`.
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke SmithReturning `false` from a callback is supported as an alternative to calling
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith`e.preventDefault(); e.stopPropagation();`. However, it is recommended to use
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smiththe event methods.
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith@example
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith Y.one("#my-form").on("submit", function (e) {
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith e.preventDefault();
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith // proceed with ajax form submission instead...
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith });
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith@method on
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith@param {String} type The name of the event
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith@param {Function} fn The callback to execute in response to the event
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith@param {Object} [context] Override `this` object in callback
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith@param {Any} [arg*] 0..n additional arguments to supply to the subscriber
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith@return {EventHandle} A subscription handle capable of detaching that
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith subscription
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith@for Node
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith**/
64ae29f70cf52f95ff7dce4a531f576a0b805ff7Luke Smith
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY.mix(Y.Node.ATTRS, {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney offsetHeight: {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney setter: function(h) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney Y.DOM.setHeight(this._node, h);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return h;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney getter: function() {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return this._node.offsetHeight;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney offsetWidth: {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney setter: function(w) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney Y.DOM.setWidth(this._node, w);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return w;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney getter: function() {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return this._node.offsetWidth;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney});
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY.mix(Y.Node.prototype, {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney sizeTo: function(w, h) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney var node;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney if (arguments.length < 2) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney node = Y.one(w);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney w = node.get('offsetWidth');
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney h = node.get('offsetHeight');
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney this.setAttrs({
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney offsetWidth: w,
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney offsetHeight: h
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney });
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney});
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove/**
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @module node
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @submodule node-base
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove */
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeneyvar Y_Node = Y.Node;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY.mix(Y_Node.prototype, {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Makes the node visible.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * If the "transition" module is loaded, show optionally
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * animates the showing of the node using either the default
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * transition effect ('fadeIn'), or the given named effect.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method show
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @for Node
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {String} name A named Transition effect to use as the show effect.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {Object} config Options to use with the transition.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {Function} callback An optional function to run after the transition completes.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney show: function(callback) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney callback = arguments[arguments.length - 1];
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney this.toggleView(true, callback);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return this;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * The implementation for showing nodes.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Default is to toggle the style.display property.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @method _show
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney _show: function() {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney this.setStyle('display', '');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney _isHidden: function() {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return Y.DOM.getStyle(this._node, 'display') === 'none';
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney toggleView: function(on, callback) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney this._toggleView.apply(this, arguments);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney _toggleView: function(on, callback) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney callback = arguments[arguments.length - 1];
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove // base on current state if not forcing
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney if (typeof on != 'boolean') {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney on = (this._isHidden()) ? 1 : 0;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney if (on) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney this._show();
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney } else {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney this._hide();
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney if (typeof callback == 'function') {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney callback.call(this);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return this;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Hides the node.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * If the "transition" module is loaded, hide optionally
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * animates the hiding of the node using either the default
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * transition effect ('fadeOut'), or the given named effect.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method hide
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {String} name A named Transition effect to use as the show effect.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {Object} config Options to use with the transition.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {Function} callback An optional function to run after the transition completes.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney hide: function(callback) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney callback = arguments[arguments.length - 1];
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney this.toggleView(false, callback);
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney return this;
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * The implementation for hiding nodes.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Default is to toggle the style.display property.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @method _hide
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney _hide: function() {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney this.setStyle('display', 'none');
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney }
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney});
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt SweeneyY.NodeList.importMethod(Y.Node.prototype, [
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Makes each node visible.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * If the "transition" module is loaded, show optionally
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * animates the showing of the node using either the default
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * transition effect ('fadeIn'), or the given named effect.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method show
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {String} name A named Transition effect to use as the show effect.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {Object} config Options to use with the transition.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {Function} callback An optional function to run after the transition completes.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @for NodeList
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'show',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /**
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * Hides each node.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * If the "transition" module is loaded, hide optionally
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * animates the hiding of the node using either the default
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * transition effect ('fadeOut'), or the given named effect.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method hide
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {String} name A named Transition effect to use as the show effect.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {Object} config Options to use with the transition.
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @param {Function} callback An optional function to run after the transition completes.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @chainable
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'hide',
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'toggleView'
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney]);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glassif (!Y.config.doc.documentElement.hasAttribute) { // IE < 8
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.Node.prototype.hasAttribute = function(attr) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (attr === 'value') {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (this.get('value') !== "") { // IE < 8 fails to populate specified when set in HTML
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return true;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return !!(this._node.attributes[attr] &&
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this._node.attributes[attr].specified);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass}
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// IE throws an error when calling focus() on an element that's invisible, not
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// displayed, or disabled.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassY.Node.prototype.focus = function () {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass try {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this._node.focus();
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } catch (e) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('error focusing node: ' + e.toString(), 'error', 'node');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass};
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// IE throws error when setting input.type = 'hidden',
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// input.setAttribute('type', 'hidden') and input.attributes.type.value = 'hidden'
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassY.Node.ATTRS.type = {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass setter: function(val) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (val === 'hidden') {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass try {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this._node.type = 'hidden';
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } catch(e) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this.setStyle('display', 'none');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this._inputType = 'hidden';
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass try { // IE errors when changing the type from "hidden'
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this._node.type = val;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } catch (e) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.log('error setting type: ' + val, 'info', 'node');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return val;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass getter: function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this._inputType || this._node.type;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass },
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _bypassProxy: true // don't update DOM when using with Attribute
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass};
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glassif (Y.config.doc.createElement('form').elements.nodeType) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // IE: elements collection is also FORM node which trips up scrubVal.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.Node.ATTRS.elements = {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass getter: function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this.all('input, textarea, button, select');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass };
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass}
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney/**
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * Provides methods for managing custom Node data.
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney *
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @module node
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @main node
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @submodule node-data
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney */
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt SweeneyY.mix(Y.Node.prototype, {
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney _initData: function() {
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney if (! ('_data' in this)) {
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney this._data = {};
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney }
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney },
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney /**
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @method getData
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @description Retrieves arbitrary data stored on a Node instance.
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * If no data is associated with the Node, it will attempt to retrieve
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * a value from the corresponding HTML data attribute. (e.g. node.getData('foo')
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * will check node.getAttribute('data-foo')).
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @param {string} name Optional name of the data field to retrieve.
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * If no name is given, all data is returned.
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @return {any | Object} Whatever is stored at the given field,
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * or an object hash of all fields.
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney */
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney getData: function(name) {
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney this._initData();
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney var data = this._data,
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney ret = data;
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney if (arguments.length) { // single field
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney if (name in data) {
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney ret = data[name];
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney } else { // initialize from HTML attribute
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney ret = this._getDataAttribute(name);
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney }
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney } else if (typeof data == 'object' && data !== null) { // all fields
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney ret = {};
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney Y.Object.each(data, function(v, n) {
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney ret[n] = v;
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney });
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney ret = this._getDataAttributes(ret);
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney }
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney return ret;
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney },
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney _getDataAttributes: function(ret) {
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney ret = ret || {};
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney var i = 0,
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney attrs = this._node.attributes,
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney len = attrs.length,
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney prefix = this.DATA_PREFIX,
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney prefixLength = prefix.length,
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney name;
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney while (i < len) {
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney name = attrs[i].name;
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney if (name.indexOf(prefix) === 0) {
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney name = name.substr(prefixLength);
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney if (!(name in ret)) { // only merge if not already stored
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney ret[name] = this._getDataAttribute(name);
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney }
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney }
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney i += 1;
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney }
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney return ret;
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney },
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney _getDataAttribute: function(name) {
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney var name = this.DATA_PREFIX + name,
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney data;
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney if (this.hasAttribute(name)) {
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney data = this.getAttribute(name);
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney }
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney return data;
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney },
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney /**
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @method setData
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @description Stores arbitrary data on a Node instance.
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * This is not stored with the DOM node.
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @param {string} name The name of the field to set. If no name
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * is given, name is treated as the data and overrides any existing data.
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @param {any} val The value to be assigned to the field.
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @chainable
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney */
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney setData: function(name, val) {
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney this._initData();
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney if (arguments.length > 1) {
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney this._data[name] = val;
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney } else {
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney this._data = name;
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney }
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney return this;
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney },
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney /**
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @method clearData
44d4f272b35aec28ecaacadf6bc6eb497fd509d3Matt Sweeney * @description Clears internally stored data.
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @param {string} name The name of the field to clear. If no name
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * is given, all data is cleared.
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney * @chainable
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney */
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney clearData: function(name) {
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney if ('_data' in this) {
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney if (typeof name != 'undefined') {
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney delete this._data[name];
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney } else {
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney delete this._data;
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney }
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney }
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney return this;
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney }
880f76ee227b05b889736151e137e61c7bbf950dMatt Sweeney});
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt SweeneyY.mix(Y.NodeList.prototype, {
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney /**
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @method getData
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @description Retrieves arbitrary data stored on each Node instance
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * bound to the NodeList.
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @see Node
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @param {string} name Optional name of the data field to retrieve.
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * If no name is given, all data is returned.
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @return {Array} An array containing all of the data for each Node instance.
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * or an object hash of all fields.
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney */
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney getData: function(name) {
44d4f272b35aec28ecaacadf6bc6eb497fd509d3Matt Sweeney var args = (arguments.length) ? [name] : [];
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney return this._invoke('getData', args, true);
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney },
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney /**
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @method setData
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @description Stores arbitrary data on each Node instance bound to the
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * NodeList. This is not stored with the DOM node.
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @param {string} name The name of the field to set. If no name
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * is given, name is treated as the data and overrides any existing data.
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @param {any} val The value to be assigned to the field.
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @chainable
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney */
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney setData: function(name, val) {
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney var args = (arguments.length > 1) ? [name, val] : [name];
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney return this._invoke('setData', args);
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney },
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney /**
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @method clearData
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @description Clears data on all Node instances bound to the NodeList.
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @param {string} name The name of the field to clear. If no name
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * is given, all data is cleared.
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney * @chainable
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney */
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney clearData: function(name) {
44d4f272b35aec28ecaacadf6bc6eb497fd509d3Matt Sweeney var args = (arguments.length) ? [name] : [];
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney return this._invoke('clearData', [name]);
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney }
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney});
f3a7e54fed783ecf7736b0004e4cc67314eca47dMatt Sweeney
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney}, '@VERSION@' ,{requires:['dom-base', 'node-core', 'event-base']});