node-base-debug.js revision 5770dec23508300b0e77edf1fd63b699b89e4615
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
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) {
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney if (childNodes[i][TAG_NAME]) {
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 /**
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Applies an event listener to each Node bound to the NodeList.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method on
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} type The event being listened for
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Function} fn The handler to call when the event fires
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Object} context The context to call the handler with.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Default is the NodeList instance.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Object} context The context to call the handler with.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * param {mixed} arg* 0..n additional arguments to supply to the subscriber
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * when the event fires.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @return {Object} Returns an event handle that can later be use to detach().
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Event.on
1909339da3105dc509908ff39ecc298f2f94f446Ryan Grove * @for NodeList
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass */
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.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @return {Object} Returns an event handle that can later be use to detach().
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Event.on
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.
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @return {Object} Returns an event handle that can later be use to detach().
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Event.on
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.
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith * @return {Object} Returns an event handle that can later be use to detach().
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith * @see Event.on
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
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'detach',
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney /** Called on each Node instance
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @method detachAll
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney * @see Node.detachAll
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney */
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney 'detachAll'
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass]);
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
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney}, '@VERSION@' ,{requires:['dom-base', 'node-core', 'event-base']});