OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 | 3 |
4 /** | 4 /** |
5 * Provides the Charm Slider widget. | 5 * Provides the Charm Slider widget. |
6 * | 6 * |
7 * @namespace juju | 7 * @namespace juju |
8 * @module widgets | 8 * @module widgets |
9 * @submodule browser.CharmSlider | 9 * @submodule browser.CharmSlider |
10 * | 10 * |
11 */ | 11 */ |
12 YUI.add('browser-charm-slider', function(Y) { | 12 YUI.add('browser-charm-slider', function(Y) { |
13 var sub = Y.Lang.sub, | 13 var sub = Y.Lang.sub, |
14 ns = Y.namespace('juju.widgets.browser'); | 14 ns = Y.namespace('juju.widgets.browser'); |
15 | 15 |
16 /** | 16 /** |
17 * The CharmSlider provides a rotating display of one member of a generic set | 17 * The CharmSlider provides a rotating display of one member of a generic set |
18 * of items, with controls to go directly to a given item. | 18 * of items, with controls to go directly to a given item. |
19 * | 19 * |
20 * @class CharmSlider | 20 * @class CharmSlider |
21 * @extends {Y.ScrollView} | 21 * @extends {Y.ScrollView} |
22 * | 22 * |
23 */ | 23 */ |
24 ns.CharmSlider = new Y.Base.create('browser-charm-slider', Y.ScrollView, [], { | 24 ns.CharmSlider = new Y.Base.create('browser-charm-slider', Y.ScrollView, [ |
| 25 Y.Event.EventTracker |
| 26 ], { |
25 | 27 |
26 /** | 28 /** |
27 * Template for the CharmSlider | 29 * Template for the CharmSlider |
28 * | 30 * |
29 * @property charmSliderTemplate | 31 * @property charmSliderTemplate |
30 * @type {String} | 32 * @type {String} |
31 * | 33 * |
32 */ | 34 */ |
33 charmSliderTemplate: '<ul width="{width}px" />', | 35 charmSliderTemplate: '<ul width="{width}px" />', |
34 | 36 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 * Binds the navigate event listeners | 170 * Binds the navigate event listeners |
169 * | 171 * |
170 * @method bindUI | 172 * @method bindUI |
171 * @private | 173 * @private |
172 */ | 174 */ |
173 bindUI: function() { | 175 bindUI: function() { |
174 | 176 |
175 //Call the parent bindUI method | 177 //Call the parent bindUI method |
176 ns.CharmSlider.superclass.bindUI.apply(this); | 178 ns.CharmSlider.superclass.bindUI.apply(this); |
177 | 179 |
178 var events = this.get('_events'), | 180 var boundingBox = this.get('boundingBox'), |
179 boundingBox = this.get('boundingBox'), | |
180 nav = boundingBox.one('.navigation'); | 181 nav = boundingBox.one('.navigation'); |
181 events.push(this.after('render', this._startTimer, this)); | 182 this.addEvent(this.after('render', this._startTimer, this)); |
182 events.push(boundingBox.on('mouseenter', this._pauseAutoAdvance, this)); | 183 this.addEvent(boundingBox.on('mouseenter', this._pauseAutoAdvance, this)); |
183 events.push(boundingBox.on('mouseleave', this._pauseAutoAdvance, this)); | 184 this.addEvent(boundingBox.on('mouseleave', this._pauseAutoAdvance, this)); |
184 events.push(nav.delegate('click', function(e) { | 185 this.addEvent(nav.delegate('click', function(e) { |
185 var index = e.currentTarget.getAttribute('data-index'); | 186 var index = e.currentTarget.getAttribute('data-index'); |
186 index = parseInt(index, 10); | 187 index = parseInt(index, 10); |
187 this._advanceSlide(index); | 188 this._advanceSlide(index); |
188 }, 'li', this)); | 189 }, 'li', this)); |
189 }, | 190 }, |
190 | 191 |
191 /** | 192 /** |
192 * Detaches events attached during instantiation | 193 * Clean up after the widget. |
193 * | 194 * |
194 * @method destructor | 195 * @method destructor |
195 * @private | 196 * @private |
196 */ | 197 */ |
197 destructor: function() { | 198 destructor: function() { |
198 console.log('Clearing slider events'); | |
199 // Stop any in-progress timer | 199 // Stop any in-progress timer |
200 this.get('timer').cancel(); | 200 this.get('timer').cancel(); |
201 Y.Array.each(this.get('_events'), function(event) { | |
202 event.detach(); | |
203 }); | |
204 }, | 201 }, |
205 | 202 |
206 /** | 203 /** |
207 * Initializer | 204 * Initializer |
208 * | 205 * |
209 * @method initializer | 206 * @method initializer |
210 * @param {Object} The config object. | 207 * @param {Object} The config object. |
211 * | 208 * |
212 */ | 209 */ |
213 initializer: function(cfg) { | 210 initializer: function(cfg) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 * | 280 * |
284 * @method validator | 281 * @method validator |
285 * @param {Array} The items being validated. | 282 * @param {Array} The items being validated. |
286 */ | 283 */ |
287 validator: function(val) { | 284 validator: function(val) { |
288 return (val.length <= this.get('max')); | 285 return (val.length <= this.get('max')); |
289 } | 286 } |
290 }, | 287 }, |
291 | 288 |
292 /** | 289 /** |
293 * @attribute _events | |
294 * @default [] | |
295 * @type {Array} | |
296 * | |
297 */ | |
298 _events: { | |
299 value: [] | |
300 }, | |
301 | |
302 /** | |
303 * @attribute max | 290 * @attribute max |
304 * @default 5 | 291 * @default 5 |
305 * @type {Int} | 292 * @type {Int} |
306 * | 293 * |
307 */ | 294 */ |
308 max: { | 295 max: { |
309 value: 5 | 296 value: 5 |
310 }, | 297 }, |
311 | 298 |
312 /** | 299 /** |
313 * @attribute timer | 300 * @attribute timer |
314 * @default null | 301 * @default null |
315 * @type {Object} | 302 * @type {Object} |
316 * | 303 * |
317 */ | 304 */ |
318 timer: { | 305 timer: { |
319 value: null | 306 value: null |
320 } | 307 } |
321 } | 308 } |
322 }); | 309 }); |
323 | 310 |
324 }, '0.1.0', { | 311 }, '0.1.0', { |
325 requires: [ | 312 requires: [ |
326 'array-extras', | 313 'array-extras', |
327 'base', | 314 'base', |
328 'event-mouseenter', | 315 'event-mouseenter', |
| 316 'event-tracker', |
329 'scrollview', | 317 'scrollview', |
330 'scrollview-paginator' | 318 'scrollview-paginator' |
331 ] | 319 ] |
332 }); | 320 }); |
OLD | NEW |