[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* 2 YUI 3.17.2 (build 9c3c78e) 3 Copyright 2014 Yahoo! Inc. All rights reserved. 4 Licensed under the BSD License. 5 http://yuilibrary.com/license/ 6 */ 7 8 YUI.add('tree-openable', function (Y, NAME) { 9 10 /*jshint expr:true, onevar:false */ 11 12 /** 13 Extension for `Tree` that adds the concept of open/closed state for nodes. 14 15 @module tree 16 @submodule tree-openable 17 @main tree-openable 18 **/ 19 20 /** 21 Extension for `Tree` that adds the concept of open/closed state for nodes. 22 23 @class Tree.Openable 24 @constructor 25 @extensionfor Tree 26 **/ 27 28 /** 29 Fired when a node is closed. 30 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'; 37 38 /** 39 Fired when a node is opened. 40 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'; 47 48 function Openable() {} 49 50 Openable.prototype = { 51 // -- Lifecycle ------------------------------------------------------------ 52 initializer: function () { 53 this.nodeExtensions = this.nodeExtensions.concat(Y.Tree.Node.Openable); 54 }, 55 56 // -- Public Methods ------------------------------------------------------- 57 58 /** 59 Closes the specified node if it isn't already closed. 60 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 } 82 83 return this; 84 }, 85 86 /** 87 Opens the specified node if it isn't already open. 88 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 } 110 111 return this; 112 }, 113 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. 117 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 }, 133 134 // -- Default Event Handlers ----------------------------------------------- 135 136 /** 137 Default handler for the `close` event. 138 139 @method _defCloseFn 140 @param {EventFacade} e 141 @protected 142 **/ 143 _defCloseFn: function (e) { 144 delete e.node.state.open; 145 }, 146 147 /** 148 Default handler for the `open` event. 149 150 @method _defOpenFn 151 @param {EventFacade} e 152 @protected 153 **/ 154 _defOpenFn: function (e) { 155 e.node.state.open = true; 156 } 157 }; 158 159 Y.Tree.Openable = Openable; 160 /** 161 @module tree 162 @submodule tree-openable 163 **/ 164 165 /** 166 `Tree.Node` extension that adds methods useful for nodes in trees that use the 167 `Tree.Openable` extension. 168 169 @class Tree.Node.Openable 170 @constructor 171 @extensionfor Tree.Node 172 **/ 173 174 function NodeOpenable() {} 175 176 NodeOpenable.prototype = { 177 /** 178 Closes this node if it's currently open. 179 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 }, 194 195 /** 196 Returns `true` if this node is currently open. 197 198 Note: the root node of a tree is always considered to be open. 199 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 }, 206 207 /** 208 Opens this node if it's currently closed. 209 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 }, 224 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. 228 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 } 243 }; 244 245 Y.Tree.Node.Openable = NodeOpenable; 246 247 248 }, '3.17.2', {"requires": ["tree"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |