OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Controller for spinner. | 6 * Controller for spinner. |
7 * @param {!HTMLElement} element | 7 * @param {!HTMLElement} element |
8 * @param {!DirectoryModel} directoryModel | |
9 * @constructor | 8 * @constructor |
10 * @extends {cr.EventTarget} | 9 * @extends {cr.EventTarget} |
11 */ | 10 */ |
12 function SpinnerController(element, directoryModel) { | 11 function SpinnerController(element) { |
13 /** | 12 /** |
14 * The container element of the file list. | 13 * The container element of the file list. |
15 * @type {!HTMLElement} | 14 * @type {!HTMLElement} |
16 * @const | 15 * @const |
17 * @private | 16 * @private |
18 */ | 17 */ |
19 this.element_ = element; | 18 this.element_ = element; |
20 | 19 |
21 /** | 20 /** |
22 * Directory model. | |
23 * @type {!DirectoryModel} | |
24 * @const | |
25 * @private | |
26 */ | |
27 this.directoryModel_ = directoryModel; | |
28 | |
29 /** | |
30 * @type {number} | 21 * @type {number} |
31 * @private | 22 * @private |
32 */ | 23 */ |
33 this.timeoutId_ = 0; | 24 this.timeoutId_ = 0; |
34 } | 25 } |
35 | 26 |
36 SpinnerController.prototype.__proto__ = cr.EventTarget.prototype; | 27 SpinnerController.prototype.__proto__ = cr.EventTarget.prototype; |
37 | 28 |
38 /** | 29 /** |
39 * Shows the spinner. | 30 * Blinks the spinner for a short period of time. |
31 */ | |
32 SpinnerController.prototype.blink = function() { | |
hirono
2015/07/06 04:52:38
Can we hide blinking spinner when the current dire
mtomasz
2015/07/06 08:48:48
Do we need to hide it? Blinking is only one second
hirono
2015/07/06 09:39:27
I think it is worth to handle it. I'm guessing the
mtomasz
2015/07/07 03:42:10
Sebastien said he's fine with blinking the spinner
hirono
2015/07/07 03:58:22
SGTM. Thank you for confirming!
| |
33 this.element_.hidden = false; | |
34 clearTimeout(this.blinkHideTimeoutId_); | |
35 this.blinkHideTimeoutId_ = 0; | |
hirono
2015/07/06 04:52:38
Is this line needed?
mtomasz
2015/07/06 08:48:48
Done.
| |
36 this.blinkHideTimeoutId_ = setTimeout(this.hide.bind(this), 1000); | |
37 }; | |
38 | |
39 /** | |
40 * Shows the spinner until hide is called. | |
40 */ | 41 */ |
41 SpinnerController.prototype.show = function() { | 42 SpinnerController.prototype.show = function() { |
42 if (!this.directoryModel_.isScanning()) | |
43 return; | |
44 this.element_.hidden = false; | 43 this.element_.hidden = false; |
44 clearTimeout(this.blinkHideTimeoutId_); | |
45 this.blinkHideTimeoutId_ = 0; | |
45 clearTimeout(this.timeoutId_); | 46 clearTimeout(this.timeoutId_); |
46 this.timeoutId_ = 0; | 47 this.timeoutId_ = 0; |
47 var spinnerShownEvent = new Event('spinner-shown'); | 48 var spinnerShownEvent = new Event('spinner-shown'); |
48 this.dispatchEvent(spinnerShownEvent); | 49 this.dispatchEvent(spinnerShownEvent); |
49 }; | 50 }; |
50 | 51 |
51 /** | 52 /** |
52 * Hides the spinner. | 53 * Hides the spinner. |
53 */ | 54 */ |
54 SpinnerController.prototype.hide = function() { | 55 SpinnerController.prototype.hide = function() { |
55 if (this.directoryModel_.isScanning() && | |
56 this.directoryModel_.getFileList().length == 0) { | |
57 return; | |
58 } | |
59 this.element_.hidden = true; | 56 this.element_.hidden = true; |
60 clearTimeout(this.timeoutId_); | 57 clearTimeout(this.timeoutId_); |
61 this.timeoutId_ = 0; | 58 this.timeoutId_ = 0; |
59 clearTimeout(this.blinkHideTimeoutId_); | |
60 this.blinkHideTimeoutId_ = 0; | |
62 }; | 61 }; |
63 | 62 |
64 /** | 63 /** |
65 * Shows the spinner after 500ms. | 64 * Shows the spinner after 500ms (unless it's already visible). |
66 */ | 65 */ |
67 SpinnerController.prototype.showLater = function() { | 66 SpinnerController.prototype.showLater = function() { |
68 if (!this.element_.hidden) | 67 if (!this.element_.hidden) |
hirono
2015/07/06 09:39:27
I think we should clear blinkHideTimeout here.
bl
mtomasz
2015/07/07 03:42:11
Good point. Done.
| |
69 return; | 68 return; |
70 clearTimeout(this.timeoutId_); | 69 clearTimeout(this.timeoutId_); |
71 this.timeoutId_ = setTimeout(this.show.bind(this), 500); | 70 this.timeoutId_ = setTimeout(this.show.bind(this), 500); |
72 }; | 71 }; |
OLD | NEW |