NOBUG: Fixed file access permissions
[moodle.git] / lib / yuilib / 3.13.0 / tree-openable / tree-openable-debug.js
blobd0b17d58e4fc2c361e05c28acffd19e4373ff971
1 /*
2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
8 YUI.add('tree-openable', function (Y, NAME) {
10 /*jshint expr:true, onevar:false */
12 /**
13 Extension for `Tree` that adds the concept of open/closed state for nodes.
15 @module tree
16 @submodule tree-openable
17 @main tree-openable
18 **/
20 /**
21 Extension for `Tree` that adds the concept of open/closed state for nodes.
23 @class Tree.Openable
24 @constructor
25 @extensionfor Tree
26 **/
28 /**
29 Fired when a node is closed.
31 @event close
32 @param {Tree.Node} node Node being closed.
33 @param {String} src Source of the event.
34 @preventable _defCloseFn
35 **/
36 var EVT_CLOSE = 'close';
38 /**
39 Fired when a node is opened.
41 @event open
42 @param {Tree.Node} node Node being opened.
43 @param {String} src Source of the event.
44 @preventable _defOpenFn
45 **/
46 var EVT_OPEN = 'open';
48 function Openable() {}
50 Openable.prototype = {
51     // -- Lifecycle ------------------------------------------------------------
52     initializer: function () {
53         this.nodeExtensions = this.nodeExtensions.concat(Y.Tree.Node.Openable);
54     },
56     // -- Public Methods -------------------------------------------------------
58     /**
59     Closes the specified node if it isn't already closed.
61     @method closeNode
62     @param {Tree.Node} node Node to close.
63     @param {Object} [options] Options.
64         @param {Boolean} [options.silent=false] If `true`, the `close` event
65             will be suppressed.
66         @param {String} [options.src] Source of the change, to be passed along
67             to the event facade of the resulting event. This can be used to
68             distinguish between changes triggered by a user and changes
69             triggered programmatically, for example.
70     @chainable
71     **/
72     closeNode: function (node, options) {
73         if (node.canHaveChildren && node.isOpen()) {
74             this._fireTreeEvent(EVT_CLOSE, {
75                 node: node,
76                 src : options && options.src
77             }, {
78                 defaultFn: this._defCloseFn,
79                 silent   : options && options.silent
80             });
81         }
83         return this;
84     },
86     /**
87     Opens the specified node if it isn't already open.
89     @method openNode
90     @param {Tree.Node} node Node to open.
91     @param {Object} [options] Options.
92         @param {Boolean} [options.silent=false] If `true`, the `open` event
93             will be suppressed.
94         @param {String} [options.src] Source of the change, to be passed along
95             to the event facade of the resulting event. This can be used to
96             distinguish between changes triggered by a user and changes
97             triggered programmatically, for example.
98     @chainable
99     **/
100     openNode: function (node, options) {
101         if (node.canHaveChildren && !node.isOpen()) {
102             this._fireTreeEvent(EVT_OPEN, {
103                 node: node,
104                 src : options && options.src
105             }, {
106                 defaultFn: this._defOpenFn,
107                 silent   : options && options.silent
108             });
109         }
111         return this;
112     },
114     /**
115     Toggles the open/closed state of the specified node, closing it if it's
116     currently open or opening it if it's currently closed.
118     @method toggleOpenNode
119     @param {Tree.Node} node Node to toggle.
120     @param {Object} [options] Options.
121         @param {Boolean} [options.silent=false] If `true`, events will be
122             suppressed.
123         @param {String} [options.src] Source of the change, to be passed along
124             to the event facade of the resulting event. This can be used to
125             distinguish between changes triggered by a user and changes
126             triggered programmatically, for example.
127     @chainable
128     **/
129     toggleOpenNode: function (node, options) {
130         return node.isOpen() ? this.closeNode(node, options) :
131             this.openNode(node, options);
132     },
134     // -- Default Event Handlers -----------------------------------------------
136     /**
137     Default handler for the `close` event.
139     @method _defCloseFn
140     @param {EventFacade} e
141     @protected
142     **/
143     _defCloseFn: function (e) {
144         delete e.node.state.open;
145     },
147     /**
148     Default handler for the `open` event.
150     @method _defOpenFn
151     @param {EventFacade} e
152     @protected
153     **/
154     _defOpenFn: function (e) {
155         e.node.state.open = true;
156     }
159 Y.Tree.Openable = Openable;
161 @module tree
162 @submodule tree-openable
166 `Tree.Node` extension that adds methods useful for nodes in trees that use the
167 `Tree.Openable` extension.
169 @class Tree.Node.Openable
170 @constructor
171 @extensionfor Tree.Node
174 function NodeOpenable() {}
176 NodeOpenable.prototype = {
177     /**
178     Closes this node if it's currently open.
180     @method close
181     @param {Object} [options] Options.
182         @param {Boolean} [options.silent=false] If `true`, the `close` event
183             will be suppressed.
184         @param {String} [options.src] Source of the change, to be passed along
185             to the event facade of the resulting event. This can be used to
186             distinguish between changes triggered by a user and changes
187             triggered programmatically, for example.
188     @chainable
189     **/
190     close: function (options) {
191         this.tree.closeNode(this, options);
192         return this;
193     },
195     /**
196     Returns `true` if this node is currently open.
198     Note: the root node of a tree is always considered to be open.
200     @method isOpen
201     @return {Boolean} `true` if this node is currently open, `false` otherwise.
202     **/
203     isOpen: function () {
204         return !!this.state.open || this.isRoot();
205     },
207     /**
208     Opens this node if it's currently closed.
210     @method open
211     @param {Object} [options] Options.
212         @param {Boolean} [options.silent=false] If `true`, the `open` event
213             will be suppressed.
214         @param {String} [options.src] Source of the change, to be passed along
215             to the event facade of the resulting event. This can be used to
216             distinguish between changes triggered by a user and changes
217             triggered programmatically, for example.
218     @chainable
219     **/
220     open: function (options) {
221         this.tree.openNode(this, options);
222         return this;
223     },
225     /**
226     Toggles the open/closed state of this node, closing it if it's currently
227     open or opening it if it's currently closed.
229     @method toggleOpen
230     @param {Object} [options] Options.
231         @param {Boolean} [options.silent=false] If `true`, events will be
232             suppressed.
233         @param {String} [options.src] Source of the change, to be passed along
234             to the event facade of the resulting event. This can be used to
235             distinguish between changes triggered by a user and changes
236             triggered programmatically, for example.
237     @chainable
238     **/
239     toggleOpen: function (options) {
240         this.tree.toggleOpenNode(this, options);
241         return this;
242     }
245 Y.Tree.Node.Openable = NodeOpenable;
248 }, '3.13.0', {"requires": ["tree"]});