8346e283ad797ef549be70335d3961f4324901baRyan Grove/**
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @module node
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @submodule node-base
8346e283ad797ef549be70335d3961f4324901baRyan Grove */
8346e283ad797ef549be70335d3961f4324901baRyan Grove
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeneyvar Y_Node = Y.Node,
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney Y_DOM = Y.DOM;
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney/**
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Static collection of configuration attributes for special handling
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @property ATTRS
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @static
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @type object
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt SweeneyY_Node.ATTRS = {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney /**
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Allows for getting and setting the text of an element.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Formatting is preserved and special characters are treated literally.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @config text
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @type String
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney text: {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney getter: function() {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney return Y_DOM.getText(this._node);
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney },
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney setter: function(content) {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney Y_DOM.setText(this._node, content);
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney return content;
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney }
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney },
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney /**
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Allows for getting and setting the text of an element.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Formatting is preserved and special characters are treated literally.
5b1c89071eae2ae83f92260d7a50f9ad4e574f3dMatt Sweeney * @config for
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @type String
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney 'for': {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney getter: function() {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney return Y_DOM.getAttribute(this._node, 'for');
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney },
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney setter: function(val) {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney Y_DOM.setAttribute(this._node, 'for', val);
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney return val;
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney }
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney },
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney 'options': {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney getter: function() {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney return this._node.getElementsByTagName('option');
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney }
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney },
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney /**
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Returns a NodeList instance of all HTMLElement children.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @readOnly
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @config children
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @type NodeList
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney 'children': {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney getter: function() {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney var node = this._node,
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney children = node.children,
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney childNodes, i, len;
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney if (!children) {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney childNodes = node.childNodes;
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney children = [];
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney for (i = 0, len = childNodes.length; i < len; ++i) {
8f9dd8c743b57afd427fb6be634aee74466ad400Matt Sweeney if (childNodes[i].tagName) {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney children[children.length] = childNodes[i];
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney }
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney }
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney }
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney return Y.all(children);
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney }
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney },
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney value: {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney getter: function() {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney return Y_DOM.getValue(this._node);
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney },
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney setter: function(val) {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney Y_DOM.setValue(this._node, val);
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney return val;
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney }
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney }
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney};
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt SweeneyY.Node.importMethod(Y.DOM, [
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney /**
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Allows setting attributes on DOM nodes, normalizing in some cases.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * This passes through to the DOM node, allowing for custom attributes.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @method setAttribute
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @for Node
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @for NodeList
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @chainable
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {string} name The attribute name
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @param {string} value The value to set
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney 'setAttribute',
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney /**
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Allows getting attributes on DOM nodes, normalizing in some cases.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * This passes through to the DOM node, allowing for custom attributes.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @method getAttribute
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @for Node
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @for NodeList
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {string} name The attribute name
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @return {string} The attribute value
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney 'getAttribute'
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney]);