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

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: Add back space on top of 'Learn More' link Created 6 years, 1 month 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 | « no previous file | chrome/browser/resources/hotword_audio_verification/manifest.json » ('j') | 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 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 var closeAppWindow = function(e) {
12 var closeButtons = document.getElementsByClassName('close'); 12 var classes = e.target.classList;
13 for (var i = 0; i < closeButtons.length; ++i) { 13 if (classes.contains('close') || classes.contains('finish-button')) {
14 var closeButton = closeButtons[i];
15 closeButton.addEventListener('click', function(e) {
16 appWindow.close(); 14 appWindow.close();
17 e.preventDefault(); 15 e.preventDefault();
18 }); 16 }
19 } 17 };
20 18
21 $('ah-cancel-button').addEventListener('click', function(e) { 19 // TODO(kcarattini): Cancel training in NaCl module for hotword-only and
22 appWindow.close(); 20 // speech-training close and cancel buttons.
23 e.preventDefault(); 21 $('steps').addEventListener('click', closeAppWindow);
24 });
25
26 $('done-button').addEventListener('click', function(e) {
27 appWindow.close();
28 e.preventDefault();
29 });
30
31 $('ho-cancel-button').addEventListener('click', function(e) {
32 appWindow.close();
33 e.preventDefault();
34 });
35
36 $('hw-cancel-button').addEventListener('click', function(e) {
37 appWindow.close();
38 e.preventDefault();
39 });
40
41 $('st-cancel-button').addEventListener('click', function(e) {
42 appWindow.close();
43 e.preventDefault();
44 });
45
46 $('ah-agree-button').addEventListener('click', function(e) {
47 // TODO(kcarattini): Set the Audio History setting.
48 appWindow.close();
49 e.preventDefault();
50 });
51 22
52 $('hw-agree-button').addEventListener('click', function(e) { 23 $('hw-agree-button').addEventListener('click', function(e) {
53 flow.advanceStep(); 24 flow.advanceStep();
54 e.preventDefault(); 25 e.preventDefault();
55 }); 26 });
56 27
57 // TODO(kcarattini): Remove this once speech training is implemented. The 28 $('settings-link').addEventListener('click', function(e) {
58 // way to get to the next page will be to complete the speech training. 29 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(); 30 e.preventDefault();
68 }); 31 });
69 32
70 // TODO(kcarattini): Remove this once speech training is implemented. The 33 /**
71 // way to get to the next page will be to complete the speech training. 34 * Updates steps of the training UI.
72 $('ho-training').addEventListener('click', function(e) { 35 * @param {string} pagePrefix Prefix of the element ids for this page.
73 if (chrome.hotwordPrivate.setAudioLoggingEnabled) 36 * @param {Event} e The click event.
74 chrome.hotwordPrivate.setAudioLoggingEnabled(true, function() {}); 37 */
38 function doTraining(pagePrefix, e) {
39 // TODO(kcarattini): Update this to respond to a hotword trigger once
40 // speech training is implemented.
41 var steps = $(pagePrefix + '-training').querySelectorAll('.train');
42 var index = Array.prototype.indexOf.call(steps, e.currentTarget);
43 if (!steps[index])
44 return;
75 45
76 if (chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled) { 46 // TODO(kcarattini): Localize this string.
77 chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled(true, 47 steps[index].querySelector('.text').textContent = 'Recorded';
78 flow.advanceStep.bind(flow)); 48 steps[index].classList.remove('listening');
49 steps[index].classList.add('recorded');
50
51 if (steps[index + 1]) {
52 steps[index + 1].classList.remove('not-started');
53 steps[index + 1].classList.add('listening');
79 } 54 }
80 e.preventDefault(); 55 }
81 }); 56
57 /**
58 * Adds event listeners to the training UI.
59 * @param {string} pagePrefix Prefix of the element ids for this page.
60 */
61 function addTrainingEventListeners(pagePrefix) {
62 var steps = $(pagePrefix + '-training').querySelectorAll('.train');
63 for (var i = 0; i < steps.length; ++i) {
64 steps[i].addEventListener('click', function(e) {
65 doTraining(pagePrefix, e);
66 e.preventDefault();
67
68 if (e.currentTarget != steps[steps.length - 1])
69 return;
70
71 // Update the 'Cancel' button.
72 var buttonElem = $(pagePrefix + '-cancel-button');
73 // TODO(kcarattini): Localize this string.
74 buttonElem.textContent = 'Please wait ...';
75 buttonElem.classList.add('grayed-out');
76 buttonElem.classList.remove('finish-button');
77
78 setTimeout(function() {
79 if (chrome.hotwordPrivate.setAudioLoggingEnabled)
80 chrome.hotwordPrivate.setAudioLoggingEnabled(true, function() {});
81
82 if (chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled) {
83 chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled(true,
84 flow.advanceStep.bind(flow));
85 }
86 }, 2000);
87 });
88 }
89 }
90
91 addTrainingEventListeners('speech-training');
92 addTrainingEventListeners('hotword-only');
82 }); 93 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/hotword_audio_verification/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698