Version 3.17.2
Show:

File: node/js/node-class.js

  1. /**
  2. * @module node
  3. * @submodule node-base
  4. */
  5.  
  6. var methods = [
  7. /**
  8. * Determines whether the node has the given className.
  9. * @method hasClass
  10. * @for Node
  11. * @param {String} className the class name to search for
  12. * @return {Boolean} Whether or not the node has the specified class
  13. */
  14. 'hasClass',
  15.  
  16. /**
  17. * Adds a class name to the node.
  18. * @method addClass
  19. * @param {String} className the class name to add to the node's class attribute
  20. * @chainable
  21. */
  22. 'addClass',
  23.  
  24. /**
  25. * Removes a class name from the node.
  26. * @method removeClass
  27. * @param {String} className the class name to remove from the node's class attribute
  28. * @chainable
  29. */
  30. 'removeClass',
  31.  
  32. /**
  33. * Replace a class with another class on the node.
  34. * If no oldClassName is present, the newClassName is simply added.
  35. * @method replaceClass
  36. * @param {String} oldClassName the class name to be replaced
  37. * @param {String} newClassName the class name that will be replacing the old class name
  38. * @chainable
  39. */
  40. 'replaceClass',
  41.  
  42. /**
  43. * If the className exists on the node it is removed, if it doesn't exist it is added.
  44. * @method toggleClass
  45. * @param {String} className the class name to be toggled
  46. * @param {Boolean} force Option to force adding or removing the class.
  47. * @chainable
  48. */
  49. 'toggleClass'
  50. ];
  51.  
  52. Y.Node.importMethod(Y.DOM, methods);
  53. /**
  54. * Determines whether each node has the given className.
  55. * @method hasClass
  56. * @see Node.hasClass
  57. * @for NodeList
  58. * @param {String} className the class name to search for
  59. * @return {Array} An array of booleans for each node bound to the NodeList.
  60. */
  61.  
  62. /**
  63. * Adds a class name to each node.
  64. * @method addClass
  65. * @see Node.addClass
  66. * @param {String} className the class name to add to each node's class attribute
  67. * @chainable
  68. */
  69.  
  70. /**
  71. * Removes a class name from each node.
  72. * @method removeClass
  73. * @see Node.removeClass
  74. * @param {String} className the class name to remove from each node's class attribute
  75. * @chainable
  76. */
  77.  
  78. /**
  79. * Replace a class with another class for each node.
  80. * If no oldClassName is present, the newClassName is simply added.
  81. * @method replaceClass
  82. * @see Node.replaceClass
  83. * @param {String} oldClassName the class name to be replaced
  84. * @param {String} newClassName the class name that will be replacing the old class name
  85. * @chainable
  86. */
  87.  
  88. /**
  89. * For each node, if the className exists on the node it is removed, if it doesn't exist it is added.
  90. * @method toggleClass
  91. * @see Node.toggleClass
  92. * @param {String} className the class name to be toggled
  93. * @chainable
  94. */
  95. Y.NodeList.importMethod(Y.Node.prototype, methods);
  96.