OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 function $(criterion) { | |
6 return document.querySelector(criterion); | |
7 } | |
8 | |
9 var cyclerUI = new (function () { | |
10 | |
11 /** | |
12 * Enum for different UI states, either capture or playback. | |
Jeffrey Yasskin
2012/08/15 01:03:59
You can omit "capture or playback" since those are
clintstaley
2012/08/15 23:54:20
Done.
| |
13 * @enum {number} | |
14 * @private | |
15 */ | |
16 var EnableState_ = {capture: 0, playback: 1}; | |
17 | |
18 // Members for all UI elements subject to programmatic adjustment. | |
19 this.captureTab_ = $('#capture-tab'); | |
20 this.captureTabLabel_ = $('#capture-tab-label'); | |
21 | |
22 this.playbackTab_ = $('#playback-tab'); | |
23 this.playbackTabLabel_ = $('#playback-tab-label'); | |
24 | |
25 this.popupDialog_ = $('#popup'); | |
26 this.popupContent_ = $('#popup-content'); | |
27 this.doPopupDismiss_ = $('#do-popup-dismiss'); | |
28 | |
29 /** | |
30 * Name of the most recent capture made, or the one most recently chosen | |
31 * for playback. | |
32 * @type {!string} | |
33 */ | |
34 Object.defineProperty(this, 'currentCaptureName', | |
Jeffrey Yasskin
2012/08/15 01:03:59
Why use defineProperty instead of simple assignmen
clintstaley
2012/08/15 23:54:20
Seemed it was widely used in other webui JS, and a
Jeffrey Yasskin
2012/08/16 20:19:31
I think the good OO practice is to write getters a
clintstaley
2012/08/17 04:12:25
This way in C# too. Wish they'd add properties to
| |
35 {value: null, writable: true}); | |
36 | |
37 this.cyclerData_ = new CyclerData(); | |
38 this.playbackTab_ = new PlaybackTab(this, this.cyclerData_); | |
Jeffrey Yasskin
2012/08/15 01:03:59
This overwrites an existing variable. Which did yo
clintstaley
2012/08/15 23:54:20
Oops :). Thanks. (Ditto for captureTab, of cours
| |
39 this.captureTab_ = new CaptureTab(this, this.cyclerData_, this.playbackTab_); | |
40 | |
41 /* | |
42 * Enable the capture tab, changing tab labels approproiately. | |
43 * @private | |
44 */ | |
45 this.enableCapture_ = function() { | |
46 if (this.enableState != EnableState_.capture) { | |
Jeffrey Yasskin
2012/08/15 01:03:59
Where does enableState get initialized? I guess th
clintstaley
2012/08/15 23:54:20
Yes, that was my intent. Wasn't sure if it was goo
| |
47 this.enableState = EnableState_.capture; | |
48 | |
49 this.captureTabLabel_.classList.add('selected'); | |
50 this.captureTab_.enable(); | |
Jeffrey Yasskin
2012/08/15 01:03:59
Arguably, it seems like CaptureTab.enable should i
clintstaley
2012/08/15 23:54:20
It also would have to know to deselect all the oth
| |
51 | |
52 this.playbackTabLabel_.classList.remove('selected'); | |
53 this.playbackTab_.disable(); | |
54 } | |
55 }; | |
56 | |
57 /* | |
58 * Enable the playback tab, changing tab labels approproiately. | |
59 * @private | |
60 */ | |
61 this.enablePlayback_ = function() { | |
62 if (this.enableState != EnableState_.playback) { | |
63 this.enableState = EnableState_.playback; | |
64 | |
65 this.captureTabLabel_.classList.remove('selected'); | |
66 this.captureTab_.disable(); | |
67 | |
68 this.playbackTabLabel_.classList.add('selected'); | |
69 this.playbackTab_.enable(); | |
70 } | |
71 }; | |
72 | |
73 /** | |
74 * Show an overlay with a message, a dismiss button with configurable | |
75 * label, and an action to call upon dismissal. | |
76 * @param {!string} content The message to display. | |
77 * @param {!string} dismissLabel The label on the dismiss button. | |
78 * @param {function()} action Additional action to take, if any, upon | |
79 * dismissal. | |
80 */ | |
81 this.showMessage = function(content, dismissLabel, action) { | |
82 this.popupContent_.innerText = content; | |
83 this.doPopupDismiss_.innerText = dismissLabel; | |
84 this.popupDialog_.hidden = false; | |
85 if (action != null) | |
86 doPopupDismiss_.addEventListener('click', action); | |
87 } | |
88 | |
89 /** | |
90 * Default action for popup dismissal button, performed in addition to | |
91 * any other actions that may be specified in showMessage_ call. | |
92 * @private | |
93 */ | |
94 this.clearMessage_ = function() { | |
95 this.popupDialog_.hidden = true; | |
96 } | |
97 | |
98 // Set up listeners on all buttons. | |
99 this.doPopupDismiss_.addEventListener('click', this.clearMessage_.bind(this)); | |
100 | |
101 // Set up listeners on tab labels. | |
102 this.captureTabLabel_.addEventListener('click', | |
103 this.enableCapture_.bind(this)); | |
104 this.playbackTabLabel_.addEventListener('click', | |
105 this.enablePlayback_.bind(this)); | |
106 | |
107 // Start with capture tab displayed. | |
108 this.enableCapture_(); | |
109 })(); | |
OLD | NEW |