API Docs for: 3.8.0
Show:

File: node/js/node-imports.js

  1. /**
  2.  * @module node
  3.  * @submodule node-core
  4.  */

  5. Y.Array.each([
  6.     /**
  7.      * Passes through to DOM method.
  8.      * @for Node
  9.      * @method removeChild
  10.      * @param {HTMLElement | Node} node Node to be removed
  11.      * @return {Node} The removed node
  12.      */
  13.     'removeChild',

  14.     /**
  15.      * Passes through to DOM method.
  16.      * @method hasChildNodes
  17.      * @return {Boolean} Whether or not the node has any childNodes
  18.      */
  19.     'hasChildNodes',

  20.     /**
  21.      * Passes through to DOM method.
  22.      * @method cloneNode
  23.      * @param {Boolean} deep Whether or not to perform a deep clone, which includes
  24.      * subtree and attributes
  25.      * @return {Node} The clone
  26.      */
  27.     'cloneNode',

  28.     /**
  29.      * Passes through to DOM method.
  30.      * @method hasAttribute
  31.      * @param {String} attribute The attribute to test for
  32.      * @return {Boolean} Whether or not the attribute is present
  33.      */
  34.     'hasAttribute',

  35.     /**
  36.      * Passes through to DOM method.
  37.      * @method scrollIntoView
  38.      * @chainable
  39.      */
  40.     'scrollIntoView',

  41.     /**
  42.      * Passes through to DOM method.
  43.      * @method getElementsByTagName
  44.      * @param {String} tagName The tagName to collect
  45.      * @return {NodeList} A NodeList representing the HTMLCollection
  46.      */
  47.     'getElementsByTagName',

  48.     /**
  49.      * Passes through to DOM method.
  50.      * @method focus
  51.      * @chainable
  52.      */
  53.     'focus',

  54.     /**
  55.      * Passes through to DOM method.
  56.      * @method blur
  57.      * @chainable
  58.      */
  59.     'blur',

  60.     /**
  61.      * Passes through to DOM method.
  62.      * Only valid on FORM elements
  63.      * @method submit
  64.      * @chainable
  65.      */
  66.     'submit',

  67.     /**
  68.      * Passes through to DOM method.
  69.      * Only valid on FORM elements
  70.      * @method reset
  71.      * @chainable
  72.      */
  73.     'reset',

  74.     /**
  75.      * Passes through to DOM method.
  76.      * @method select
  77.      * @chainable
  78.      */
  79.      'select',

  80.     /**
  81.      * Passes through to DOM method.
  82.      * Only valid on TABLE elements
  83.      * @method createCaption
  84.      * @chainable
  85.      */
  86.     'createCaption'

  87. ], function(method) {
  88.     Y.log('adding: ' + method, 'info', 'node');
  89.     Y.Node.prototype[method] = function(arg1, arg2, arg3) {
  90.         var ret = this.invoke(method, arg1, arg2, arg3);
  91.         return ret;
  92.     };
  93. });

  94. /**
  95.  * Passes through to DOM method.
  96.  * @method removeAttribute
  97.  * @param {String} attribute The attribute to be removed
  98.  * @chainable
  99.  */
  100.  // one-off implementation due to IE returning boolean, breaking chaining
  101. Y.Node.prototype.removeAttribute = function(attr) {
  102.     var node = this._node;
  103.     if (node) {
  104.         node.removeAttribute(attr, 0); // comma zero for IE < 8 to force case-insensitive
  105.     }

  106.     return this;
  107. };

  108. Y.Node.importMethod(Y.DOM, [
  109.     /**
  110.      * Determines whether the node is an ancestor of another HTML element in the DOM hierarchy.
  111.      * @method contains
  112.      * @param {Node | HTMLElement} needle The possible node or descendent
  113.      * @return {Boolean} Whether or not this node is the needle its ancestor
  114.      */
  115.     'contains',
  116.     /**
  117.      * Allows setting attributes on DOM nodes, normalizing in some cases.
  118.      * This passes through to the DOM node, allowing for custom attributes.
  119.      * @method setAttribute
  120.      * @for Node
  121.      * @chainable
  122.      * @param {string} name The attribute name
  123.      * @param {string} value The value to set
  124.      */
  125.     'setAttribute',
  126.     /**
  127.      * Allows getting attributes on DOM nodes, normalizing in some cases.
  128.      * This passes through to the DOM node, allowing for custom attributes.
  129.      * @method getAttribute
  130.      * @for Node
  131.      * @param {string} name The attribute name
  132.      * @return {string} The attribute value
  133.      */
  134.     'getAttribute',

  135.     /**
  136.      * Wraps the given HTML around the node.
  137.      * @method wrap
  138.      * @param {String} html The markup to wrap around the node.
  139.      * @chainable
  140.      * @for Node
  141.      */
  142.     'wrap',

  143.     /**
  144.      * Removes the node's parent node.
  145.      * @method unwrap
  146.      * @chainable
  147.      */
  148.     'unwrap',

  149.     /**
  150.      * Applies a unique ID to the node if none exists
  151.      * @method generateID
  152.      * @return {String} The existing or generated ID
  153.      */
  154.     'generateID'
  155. ]);

  156. Y.NodeList.importMethod(Y.Node.prototype, [
  157. /**
  158.  * Allows getting attributes on DOM nodes, normalizing in some cases.
  159.  * This passes through to the DOM node, allowing for custom attributes.
  160.  * @method getAttribute
  161.  * @see Node
  162.  * @for NodeList
  163.  * @param {string} name The attribute name
  164.  * @return {string} The attribute value
  165.  */

  166.     'getAttribute',
  167. /**
  168.  * Allows setting attributes on DOM nodes, normalizing in some cases.
  169.  * This passes through to the DOM node, allowing for custom attributes.
  170.  * @method setAttribute
  171.  * @see Node
  172.  * @for NodeList
  173.  * @chainable
  174.  * @param {string} name The attribute name
  175.  * @param {string} value The value to set
  176.  */
  177.     'setAttribute',

  178. /**
  179.  * Allows for removing attributes on DOM nodes.
  180.  * This passes through to the DOM node, allowing for custom attributes.
  181.  * @method removeAttribute
  182.  * @see Node
  183.  * @for NodeList
  184.  * @param {string} name The attribute to remove
  185.  */
  186.     'removeAttribute',
  187. /**
  188.  * Removes the parent node from node in the list.
  189.  * @method unwrap
  190.  * @chainable
  191.  */
  192.     'unwrap',
  193. /**
  194.  * Wraps the given HTML around each node.
  195.  * @method wrap
  196.  * @param {String} html The markup to wrap around the node.
  197.  * @chainable
  198.  */
  199.     'wrap',

  200. /**
  201.  * Applies a unique ID to each node if none exists
  202.  * @method generateID
  203.  * @return {String} The existing or generated ID
  204.  */
  205.     'generateID'
  206. ]);

  207.