API Docs for: 3.10.3
Show:

File: tree/js/extensions/tree-node-openable.js

  1. /**
  2. @module tree
  3. @submodule tree-openable
  4. **/
  5.  
  6. /**
  7. `Tree.Node` extension that adds methods useful for nodes in trees that use the
  8. `Tree.Openable` extension.
  9.  
  10. @class Tree.Node.Openable
  11. @constructor
  12. @extensionfor Tree.Node
  13. **/
  14.  
  15. function NodeOpenable() {}
  16.  
  17. NodeOpenable.prototype = {
  18. /**
  19. Closes this node if it's currently open.
  20.  
  21. @method close
  22. @param {Object} [options] Options.
  23. @param {Boolean} [options.silent=false] If `true`, the `close` event
  24. will be suppressed.
  25. @param {String} [options.src] Source of the change, to be passed along
  26. to the event facade of the resulting event. This can be used to
  27. distinguish between changes triggered by a user and changes
  28. triggered programmatically, for example.
  29. @chainable
  30. **/
  31. close: function (options) {
  32. this.tree.closeNode(this, options);
  33. return this;
  34. },
  35.  
  36. /**
  37. Returns `true` if this node is currently open.
  38.  
  39. Note: the root node of a tree is always considered to be open.
  40.  
  41. @method isOpen
  42. @return {Boolean} `true` if this node is currently open, `false` otherwise.
  43. **/
  44. isOpen: function () {
  45. return !!this.state.open || this.isRoot();
  46. },
  47.  
  48. /**
  49. Opens this node if it's currently closed.
  50.  
  51. @method open
  52. @param {Object} [options] Options.
  53. @param {Boolean} [options.silent=false] If `true`, the `open` event
  54. will be suppressed.
  55. @param {String} [options.src] Source of the change, to be passed along
  56. to the event facade of the resulting event. This can be used to
  57. distinguish between changes triggered by a user and changes
  58. triggered programmatically, for example.
  59. @chainable
  60. **/
  61. open: function (options) {
  62. this.tree.openNode(this, options);
  63. return this;
  64. },
  65.  
  66. /**
  67. Toggles the open/closed state of this node, closing it if it's currently
  68. open or opening it if it's currently closed.
  69.  
  70. @method toggleOpen
  71. @param {Object} [options] Options.
  72. @param {Boolean} [options.silent=false] If `true`, events will be
  73. suppressed.
  74. @param {String} [options.src] Source of the change, to be passed along
  75. to the event facade of the resulting event. This can be used to
  76. distinguish between changes triggered by a user and changes
  77. triggered programmatically, for example.
  78. @chainable
  79. **/
  80. toggleOpen: function (options) {
  81. this.tree.toggleOpenNode(this, options);
  82. return this;
  83. }
  84. };
  85.  
  86. Y.Tree.Node.Openable = NodeOpenable;
  87.