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

Side by Side Diff: chrome/browser/resources/hotword_audio_verification/main.js

Issue 666073005: Hotword Audio Verification App: UI polishes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Line length / correct close button Created 6 years, 2 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
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 var appWindow = chrome.app.window.current(); 5 var appWindow = chrome.app.window.current();
6 6
7 document.addEventListener('DOMContentLoaded', function() { 7 document.addEventListener('DOMContentLoaded', function() {
8 var flow = new Flow(); 8 var flow = new Flow();
9 flow.startFlow(); 9 flow.startFlow();
10 10
11 // Make the close buttons close the app window. 11 // Make the close buttons close the app window.
12 var closeButtons = document.getElementsByClassName('close'); 12 var closeButtons = document.getElementsByClassName('close');
13 for (var i = 0; i < closeButtons.length; ++i) { 13 for (var i = 0; i < closeButtons.length; ++i) {
14 var closeButton = closeButtons[i]; 14 var closeButton = closeButtons[i];
15 closeButton.addEventListener('click', function(e) { 15 closeButton.addEventListener('click', function(e) {
16 appWindow.close(); 16 appWindow.close();
17 e.preventDefault(); 17 e.preventDefault();
18 }); 18 });
19 } 19 }
20 20
21 var cancelTrainingHandler = function(e) {
Dan Beam 2014/10/23 23:56:00 nit: closeAppWindow
kcarattini 2014/10/24 07:02:42 Done.
22 //TODO(kcarattini): Cancel training in NaCl module.
Dan Beam 2014/10/23 23:56:01 // TODO
kcarattini 2014/10/24 07:02:42 Done.
23 appWindow.close();
24 e.preventDefault();
25 };
26
27 $('ho-cancel-button').addEventListener('click', cancelTrainingHandler);
28 $('st-cancel-button').addEventListener('click', cancelTrainingHandler);
29 $('ho-close-button').addEventListener('click', cancelTrainingHandler);
30 $('st-close-button').addEventListener('click', cancelTrainingHandler);
Dan Beam 2014/10/23 23:56:00 event delegation? http://davidwalsh.name/event-del
kcarattini 2014/10/24 07:02:41 Done.
31
21 $('ah-cancel-button').addEventListener('click', function(e) { 32 $('ah-cancel-button').addEventListener('click', function(e) {
Dan Beam 2014/10/23 23:56:01 change all of these to use closeAppWindow (that yo
kcarattini 2014/10/24 07:02:42 Done.
22 appWindow.close(); 33 appWindow.close();
23 e.preventDefault(); 34 e.preventDefault();
24 }); 35 });
25 36
26 $('done-button').addEventListener('click', function(e) { 37 $('done-button').addEventListener('click', function(e) {
27 appWindow.close(); 38 appWindow.close();
28 e.preventDefault(); 39 e.preventDefault();
29 }); 40 });
30 41
31 $('ho-cancel-button').addEventListener('click', function(e) {
32 appWindow.close();
33 e.preventDefault();
34 });
35
36 $('hw-cancel-button').addEventListener('click', function(e) { 42 $('hw-cancel-button').addEventListener('click', function(e) {
37 appWindow.close(); 43 appWindow.close();
38 e.preventDefault(); 44 e.preventDefault();
39 }); 45 });
40
41 $('st-cancel-button').addEventListener('click', function(e) {
42 appWindow.close();
43 e.preventDefault();
44 });
45 46
46 $('ah-agree-button').addEventListener('click', function(e) { 47 $('ah-agree-button').addEventListener('click', function(e) {
47 // TODO(kcarattini): Set the Audio History setting. 48 // TODO(kcarattini): Set the Audio History setting.
48 appWindow.close(); 49 appWindow.close();
49 e.preventDefault(); 50 e.preventDefault();
50 }); 51 });
51 52
52 $('hw-agree-button').addEventListener('click', function(e) { 53 $('hw-agree-button').addEventListener('click', function(e) {
53 flow.advanceStep(); 54 flow.advanceStep();
54 e.preventDefault(); 55 e.preventDefault();
55 }); 56 });
56 57
57 // TODO(kcarattini): Remove this once speech training is implemented. The 58 $('settings-link').addEventListener('click', function(e) {
58 // way to get to the next page will be to complete the speech training. 59 chrome.browser.openTab({'url': 'chrome://settings'}, function() {});
59 $('st-training').addEventListener('click', function(e) {
60 if (chrome.hotwordPrivate.setAudioLoggingEnabled)
61 chrome.hotwordPrivate.setAudioLoggingEnabled(true, function() {});
62
63 if (chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled) {
64 chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled(true,
65 flow.advanceStep.bind(flow));
66 }
67 e.preventDefault(); 60 e.preventDefault();
68 }); 61 });
69 62
70 // TODO(kcarattini): Remove this once speech training is implemented. The 63 // TODO(kcarattini): Update this to respond to a hotword trigger once
71 // way to get to the next page will be to complete the speech training. 64 // speech training is implemented.
Dan Beam 2014/10/23 23:56:00 /** * @param {string} pagePrefix Doc comment goes
kcarattini 2014/10/24 07:02:42 Done.
72 $('ho-training').addEventListener('click', function(e) { 65 function doTraining(pagePrefix, divNum) {
Dan Beam 2014/10/23 23:56:01 can't both pagePrefix and divNum be extracted via
Dan Beam 2014/10/23 23:56:01 nit: s/divNum/index or trainingStep
kcarattini 2014/10/24 07:02:41 Updated to use querySelectorAll.
kcarattini 2014/10/24 07:02:42 Done.
73 if (chrome.hotwordPrivate.setAudioLoggingEnabled) 66 $(pagePrefix + '-train-text-' + divNum).textContent = 'Recorded';
Dan Beam 2014/10/23 23:56:01 l10n?
kcarattini 2014/10/24 07:02:42 Added TODO.
74 chrome.hotwordPrivate.setAudioLoggingEnabled(true, function() {});
75 67
76 if (chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled) { 68 var divElem = $(pagePrefix + '-train-' + divNum);
77 chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled(true, 69 divElem.classList.remove('listening');
78 flow.advanceStep.bind(flow)); 70 divElem.classList.add('recorded');
71
72 if (divNum != 3) {
73 var nextDivElem = $(pagePrefix + '-train-' + (divNum + 1));
74 nextDivElem.classList.remove('not-started');
75 nextDivElem.classList.add('listening');
79 } 76 }
80 e.preventDefault(); 77 }
81 }); 78
79 function addTrainingEventListeners(pagePrefix, numDivs) {
80 for (var i = 1; i < numDivs; ++i) {
Dan Beam 2014/10/23 23:56:01 please document that this is i < numDivs instead o
kcarattini 2014/10/24 07:02:42 Done.
81 (function() {
82 var j = i;
83
84 $(pagePrefix + '-train-' + j).addEventListener('click', function(e) {
85 doTraining(pagePrefix, j);
Dan Beam 2014/10/23 23:56:01 why not just extract the index from the ID? var
kcarattini 2014/10/24 07:02:41 Updated to use querySelectorAll
86 e.preventDefault();
87 });
88 })();
Dan Beam 2014/10/23 23:56:01 if you really want to keep this self-executing ano
89 }
90
91 $(pagePrefix + '-train-' + numDivs).addEventListener('click', function(e) {
rpetterson 2014/10/23 22:24:46 why isn't this handled above?
rpetterson 2014/10/23 22:35:22 Nevermind. Missed the rest of the function below.
92 doTraining(pagePrefix, numDivs);
93
94 // Update the 'Cancel' button.
95 // TODO(kcarattini): Localize this string.
96 var buttonElem = $(pagePrefix + '-cancel-button');
97 buttonElem.textContent = 'Please wait ...';
98 buttonElem.classList.add('grayed-out');
99 buttonElem.removeEventListener('click', cancelTrainingHandler);
100
101 setTimeout(function() {
102 if (chrome.hotwordPrivate.setAudioLoggingEnabled)
103 chrome.hotwordPrivate.setAudioLoggingEnabled(true, function() {});
104
105 if (chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled) {
106 chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled(true,
107 flow.advanceStep.bind(flow));
108 }
109 e.preventDefault();
110 }, 2500);
111 });
112 }
113
114 addTrainingEventListeners('st', 3);
115 addTrainingEventListeners('ho', 3);
82 }); 116 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698