1
/* YUI 3.9.1 (build 5852) Copyright 2013 Yahoo! Inc. http://yuilibrary.com/license/ */
2
YUI.add('tree-openable', function (Y, NAME) {
4
/*jshint expr:true, onevar:false */
7
Extension for `Tree` that adds the concept of open/closed state for nodes.
10
@submodule tree-openable
15
Extension for `Tree` that adds the concept of open/closed state for nodes.
23
Fired when a node is closed.
26
@param {Tree.Node} node Node being closed.
27
@param {String} src Source of the event.
28
@preventable _defCloseFn
30
var EVT_CLOSE = 'close';
33
Fired when a node is opened.
36
@param {Tree.Node} node Node being opened.
37
@param {String} src Source of the event.
38
@preventable _defOpenFn
40
var EVT_OPEN = 'open';
42
function Openable() {}
44
Openable.prototype = {
45
// -- Lifecycle ------------------------------------------------------------
46
initializer: function () {
47
this.nodeExtensions = this.nodeExtensions.concat(Y.Tree.Node.Openable);
50
// -- Public Methods -------------------------------------------------------
53
Closes the specified node if it isn't already closed.
56
@param {Object} [options] Options.
57
@param {Boolean} [options.silent=false] If `true`, the `close` event
59
@param {String} [options.src] Source of the change, to be passed along
60
to the event facade of the resulting event. This can be used to
61
distinguish between changes triggered by a user and changes
62
triggered programmatically, for example.
65
closeNode: function (node, options) {
66
if (node.canHaveChildren && node.isOpen()) {
67
this._fireTreeEvent(EVT_CLOSE, {
69
src : options && options.src
71
defaultFn: this._defCloseFn,
72
silent : options && options.silent
80
Opens the specified node if it isn't already open.
83
@param {Object} [options] Options.
84
@param {Boolean} [options.silent=false] If `true`, the `open` event
86
@param {String} [options.src] Source of the change, to be passed along
87
to the event facade of the resulting event. This can be used to
88
distinguish between changes triggered by a user and changes
89
triggered programmatically, for example.
92
openNode: function (node, options) {
93
if (node.canHaveChildren && !node.isOpen()) {
94
this._fireTreeEvent(EVT_OPEN, {
96
src : options && options.src
98
defaultFn: this._defOpenFn,
99
silent : options && options.silent
107
Toggles the open/closed state of the specified node, closing it if it's
108
currently open or opening it if it's currently closed.
110
@method toggleOpenNode
111
@param {Tree.Node} node Node to toggle.
112
@param {Object} [options] Options.
113
@param {Boolean} [options.silent=false] If `true`, events will be
115
@param {String} [options.src] Source of the change, to be passed along
116
to the event facade of the resulting event. This can be used to
117
distinguish between changes triggered by a user and changes
118
triggered programmatically, for example.
121
toggleOpenNode: function (node, options) {
122
return node.isOpen() ? this.closeNode(node, options) :
123
this.openNode(node, options);
126
// -- Default Event Handlers -----------------------------------------------
129
Default handler for the `close` event.
132
@param {EventFacade} e
135
_defCloseFn: function (e) {
136
delete e.node.state.open;
140
Default handler for the `open` event.
143
@param {EventFacade} e
146
_defOpenFn: function (e) {
147
e.node.state.open = true;
151
Y.Tree.Openable = Openable;
154
@submodule tree-openable
158
`Tree.Node` extension that adds methods useful for nodes in trees that use the
159
`Tree.Openable` extension.
161
@class Tree.Node.Openable
163
@extensionfor Tree.Node
166
function NodeOpenable() {}
168
NodeOpenable.prototype = {
170
Closes this node if it's currently open.
173
@param {Object} [options] Options.
174
@param {Boolean} [options.silent=false] If `true`, the `close` event
176
@param {String} [options.src] Source of the change, to be passed along
177
to the event facade of the resulting event. This can be used to
178
distinguish between changes triggered by a user and changes
179
triggered programmatically, for example.
182
close: function (options) {
183
this.tree.closeNode(this, options);
188
Returns `true` if this node is currently open.
190
Note: the root node of a tree is always considered to be open.
193
@return {Boolean} `true` if this node is currently open, `false` otherwise.
195
isOpen: function () {
196
return !!this.state.open || this.isRoot();
200
Opens this node if it's currently closed.
203
@param {Object} [options] Options.
204
@param {Boolean} [options.silent=false] If `true`, the `open` event
206
@param {String} [options.src] Source of the change, to be passed along
207
to the event facade of the resulting event. This can be used to
208
distinguish between changes triggered by a user and changes
209
triggered programmatically, for example.
212
open: function (options) {
213
this.tree.openNode(this, options);
218
Toggles the open/closed state of this node, closing it if it's currently
219
open or opening it if it's currently closed.
222
@param {Object} [options] Options.
223
@param {Boolean} [options.silent=false] If `true`, events will be
225
@param {String} [options.src] Source of the change, to be passed along
226
to the event facade of the resulting event. This can be used to
227
distinguish between changes triggered by a user and changes
228
triggered programmatically, for example.
231
toggleOpen: function (options) {
232
this.tree.toggleOpenNode(this, options);
237
Y.Tree.Node.Openable = NodeOpenable;
240
}, '3.9.1', {"requires": ["tree"]});