OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 | 3 |
4 YUI.add('browser-overlay-indicator', function(Y) { | 4 YUI.add('browser-overlay-indicator', function(Y) { |
5 var sub = Y.Lang.sub, | 5 var sub = Y.Lang.sub, |
6 ns = Y.namespace('juju.widgets.browser'); | 6 ns = Y.namespace('juju.widgets.browser'); |
7 ns.OverlayIndicator = Y.Base.create('overlay-indicator', Y.Widget, [], { | 7 ns.OverlayIndicator = Y.Base.create('overlay-indicator', Y.Widget, [], { |
8 | 8 |
9 /** | 9 /** |
10 * Initializer; hides the indicator on creation. | 10 * Initializer; hides the indicator on creation. |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 * @default '/juju-ui/assets/images/loading-spinner.gif' | 154 * @default '/juju-ui/assets/images/loading-spinner.gif' |
155 * @type {string} | 155 * @type {string} |
156 */ | 156 */ |
157 loading_image: { | 157 loading_image: { |
158 value: '/juju-ui/assets/images/loading-spinner.gif' | 158 value: '/juju-ui/assets/images/loading-spinner.gif' |
159 } | 159 } |
160 | 160 |
161 } | 161 } |
162 }); | 162 }); |
163 | 163 |
| 164 /** |
| 165 * Manage indicator instances and make sure they're destroyed. |
| 166 * |
| 167 * @class IndicatorManager |
| 168 * |
| 169 */ |
| 170 ns.IndicatorManager = function() { |
| 171 this._initIndicatorManager(); |
| 172 }; |
| 173 |
| 174 ns.IndicatorManager.prototype = { |
| 175 /** |
| 176 * Init during class initialization. Add _indicators and catch destroy |
| 177 * event to clean up indicator instances. |
| 178 * |
| 179 * @method _initIndicatorManager |
| 180 * @private |
| 181 * |
| 182 */ |
| 183 _initIndicatorManager: function() { |
| 184 this._indicators = {}; |
| 185 this.on('destroy', this._destroyIndicators, this); |
| 186 }, |
| 187 |
| 188 /** |
| 189 * On destroy, run destroy on any indicator instances we have. This is a |
| 190 * method so we can hook up and test that it's called vs a closure in the |
| 191 * init. |
| 192 * |
| 193 * @method _destroyIndicators |
| 194 * @private |
| 195 * |
| 196 */ |
| 197 _destroyIndicators: function() { |
| 198 Y.Object.each(this._indicators, function(ind, key) { |
| 199 ind.destroy(); |
| 200 }); |
| 201 }, |
| 202 |
| 203 /** |
| 204 * Show/setBusy an indicator for a given node. If an indicator is already |
| 205 * attached then just show it, else create a new indicator instance on the |
| 206 * node. |
| 207 * |
| 208 * @method showIndicator |
| 209 * @param {Node} node the node to cover with the indicator. |
| 210 * |
| 211 */ |
| 212 showIndicator: function(node) { |
| 213 var id = node._yuid; |
| 214 |
| 215 if (this._indicators[id]) { |
| 216 this._indicators[id].setBusy(); |
| 217 } else { |
| 218 this._indicators[id] = new ns.OverlayIndicator({ |
| 219 target: node |
| 220 }); |
| 221 |
| 222 this._indicators[id].render(); |
| 223 this._indicators[id].setBusy(); |
| 224 } |
| 225 }, |
| 226 |
| 227 /** |
| 228 * Helper to make sure we can hide an indicator correctly. |
| 229 * |
| 230 * @method hideIndicator |
| 231 * @param {Node} node the container the indicator is currently over. |
| 232 * |
| 233 */ |
| 234 hideIndicator: function(node) { |
| 235 var id = node._yuid; |
| 236 if (this._indicators[id]) { |
| 237 this._indicators[id].success(); |
| 238 } |
| 239 } |
| 240 }; |
| 241 |
164 }, '0.1.0', { requires: [ | 242 }, '0.1.0', { requires: [ |
165 'base', | 243 'base', |
166 'node-screen', | 244 'node-screen', |
167 'widget' | 245 'widget' |
168 ]}); | 246 ]}); |
OLD | NEW |