Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: ui/file_manager/file_manager/foreground/js/spinner_controller.js

Issue 1222563005: Implement refreshing logic in Files app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/scan_controller.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
25
26 /**
27 * @type {number}
28 * @private
29 */
30 this.blinkHideTimeoutId_ = 0;
34 } 31 }
35 32
36 SpinnerController.prototype.__proto__ = cr.EventTarget.prototype; 33 SpinnerController.prototype.__proto__ = cr.EventTarget.prototype;
37 34
38 /** 35 /**
39 * Shows the spinner. 36 * Blinks the spinner for a short period of time.
37 */
38 SpinnerController.prototype.blink = function() {
39 this.element_.hidden = false;
40 clearTimeout(this.blinkHideTimeoutId_);
41 this.blinkHideTimeoutId_ = setTimeout(function() {
42 this.element_.hidden = true;
43 this.blinkHideTimeoutId_ = 0;
44 }.bind(this), 1000);
45 };
46
47 /**
48 * Shows the spinner until hide is called.
40 */ 49 */
41 SpinnerController.prototype.show = function() { 50 SpinnerController.prototype.show = function() {
42 if (!this.directoryModel_.isScanning())
43 return;
44 this.element_.hidden = false; 51 this.element_.hidden = false;
52 clearTimeout(this.blinkHideTimeoutId_);
53 this.blinkHideTimeoutId_ = 0;
45 clearTimeout(this.timeoutId_); 54 clearTimeout(this.timeoutId_);
46 this.timeoutId_ = 0; 55 this.timeoutId_ = 0;
47 var spinnerShownEvent = new Event('spinner-shown'); 56 var spinnerShownEvent = new Event('spinner-shown');
48 this.dispatchEvent(spinnerShownEvent); 57 this.dispatchEvent(spinnerShownEvent);
49 }; 58 };
50 59
51 /** 60 /**
52 * Hides the spinner. 61 * Hides the spinner.
53 */ 62 */
54 SpinnerController.prototype.hide = function() { 63 SpinnerController.prototype.hide = function() {
55 if (this.directoryModel_.isScanning() && 64 // If the current spinner is a blink, then it will hide by itself shortly.
56 this.directoryModel_.getFileList().length == 0) { 65 if (this.blinkHideTimeoutId_)
57 return; 66 return;
58 } 67
59 this.element_.hidden = true; 68 this.element_.hidden = true;
60 clearTimeout(this.timeoutId_); 69 clearTimeout(this.timeoutId_);
61 this.timeoutId_ = 0; 70 this.timeoutId_ = 0;
62 }; 71 };
63 72
64 /** 73 /**
65 * Shows the spinner after 500ms. 74 * Shows the spinner after 500ms (unless it's already visible).
66 */ 75 */
67 SpinnerController.prototype.showLater = function() { 76 SpinnerController.prototype.showLater = function() {
68 if (!this.element_.hidden) 77 if (!this.element_.hidden) {
78 // If there is an ongoing blink, then keep it visible until hide() is
79 // called.
80 clearTimeout(this.blinkHideTimeoutId_);
81 this.blinkHideTimeoutId_ = 0;
69 return; 82 return;
83 }
84
70 clearTimeout(this.timeoutId_); 85 clearTimeout(this.timeoutId_);
71 this.timeoutId_ = setTimeout(this.show.bind(this), 500); 86 this.timeoutId_ = setTimeout(this.show.bind(this), 500);
72 }; 87 };
OLDNEW
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/scan_controller.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698