Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
|
James Hawkins
2011/01/19 20:34:58
nit: 2011
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 cr.define('cr.ui', function() { | |
| 6 const Command = cr.ui.Command; | |
| 7 | |
| 8 /** | |
| 9 * Creates a new throbber element. | |
| 10 * @param {Object=} opt_propertyBag Optional properties. | |
| 11 * @constructor | |
| 12 * @extends {HTMLDivElement} | |
| 13 */ | |
| 14 var Throbber = cr.ui.define('div'); | |
| 15 | |
| 16 Throbber.prototype = { | |
| 17 __proto__: HTMLDivElement.prototype, | |
| 18 | |
| 19 /** | |
| 20 * Current animation position. | |
| 21 * @type {number} | |
| 22 * @private | |
| 23 */ | |
| 24 currentPosition_: 0, | |
| 25 | |
| 26 /** | |
| 27 * Initializes the throbber. | |
| 28 */ | |
| 29 decorate: function() { | |
| 30 this.currentPosition_ = 0; | |
| 31 if (this.visible) | |
| 32 this.startTimer_(); | |
| 33 }, | |
| 34 | |
| 35 /** | |
| 36 * Visibility of the throbber. | |
| 37 * @type {boolean} | |
| 38 */ | |
| 39 set visible(visible) { | |
| 40 if (visible) { | |
| 41 this.style.visibility = 'inherit'; | |
| 42 this.startTimer_(); | |
| 43 } else { | |
| 44 this.style.visibility = 'hidden'; | |
| 45 this.stopTimer_(); | |
| 46 } | |
| 47 }, | |
| 48 get visible() { | |
| 49 return this.style.visibility != 'hidden'; | |
|
arv (Not doing code reviews)
2011/01/19 21:11:18
Should this be using computed style?
| |
| 50 }, | |
| 51 | |
| 52 /** | |
| 53 * Switch to the next frame for the animation. | |
|
James Hawkins
2011/01/19 20:34:58
nit: Switches
| |
| 54 * @private | |
| 55 */ | |
| 56 advance_: function() { | |
|
arv (Not doing code reviews)
2011/01/19 21:11:18
You can also use local functions.
| |
| 57 this.currentPosition_ = (this.currentPosition_ - 16) % 576; | |
|
arv (Not doing code reviews)
2011/01/19 21:11:18
Please use a time based animation to prevent jerky
| |
| 58 this.style.backgroundPositionX = this.currentPosition_ + 'px'; | |
|
arv (Not doing code reviews)
2011/01/19 21:11:18
Why do we use a sprite here when we can use rotate
arv (Not doing code reviews)
2011/01/19 21:33:42
To go even further we can do the whole animation i
Sergey Ulanov
2011/01/20 02:00:49
throbber.png has shadows, so it is not just rotati
Sergey Ulanov
2011/01/20 02:00:49
Done.
| |
| 59 }, | |
| 60 | |
| 61 /** | |
| 62 * Start the animation timer. | |
|
James Hawkins
2011/01/19 20:34:58
nit: Starts
| |
| 63 * @private | |
| 64 */ | |
| 65 startTimer_: function() { | |
| 66 if (this.timer_) | |
| 67 this.stopTimer_(); | |
| 68 this.timer_ = setInterval(this.advance_.bind(this), 30); | |
|
arv (Not doing code reviews)
2011/01/19 21:11:18
Use setTimeout (so that we can easily switch to re
| |
| 69 }, | |
| 70 | |
| 71 /** | |
| 72 * Stop the animation timer. | |
|
James Hawkins
2011/01/19 20:34:58
nit: Stops
| |
| 73 * @private | |
| 74 */ | |
| 75 stopTimer_: function() { | |
| 76 if (this.timer_) { | |
| 77 clearInterval(this.timer_); | |
| 78 this.timer_ = null; | |
| 79 } | |
| 80 }, | |
| 81 }; | |
| 82 | |
| 83 // Export | |
| 84 return { | |
| 85 Throbber: Throbber | |
| 86 }; | |
| 87 }); | |
| OLD | NEW |