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 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); | |
Dan Beam
2014/10/27 16:10:33
note: this can return -1
kcarattini
2014/10/27 23:20:10
Done.
| |
75 | 43 |
76 if (chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled) { | 44 // TODO(kcarattini): Localize this string. |
77 chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled(true, | 45 steps[index].querySelector('.text').textContent = 'Recorded'; |
78 flow.advanceStep.bind(flow)); | 46 steps[index].classList.remove('listening'); |
47 steps[index].classList.add('recorded'); | |
48 | |
49 if (steps[index + 1]) { | |
50 steps[index + 1].classList.remove('not-started'); | |
51 steps[index + 1].classList.add('listening'); | |
79 } | 52 } |
80 e.preventDefault(); | 53 } |
81 }); | 54 |
55 /** | |
56 * Adds event listeners to the training UI. | |
57 * @param {string} pagePrefix Prefix of the element ids for this page. | |
58 */ | |
59 function addTrainingEventListeners(pagePrefix) { | |
60 var steps = $(pagePrefix + '-training').querySelectorAll('.train'); | |
61 for (var i = 0; i < steps.length; ++i) { | |
62 steps[i].addEventListener('click', function(e) { | |
63 doTraining(pagePrefix, e); | |
64 e.preventDefault(); | |
65 | |
66 if (e.currentTarget != steps[steps.length - 1]) | |
67 return; | |
68 | |
69 // Update the 'Cancel' button. | |
70 var buttonElem = $(pagePrefix + '-cancel-button'); | |
71 // TODO(kcarattini): Localize this string. | |
72 buttonElem.textContent = 'Please wait ...'; | |
73 buttonElem.classList.add('grayed-out'); | |
74 buttonElem.classList.remove('finish-button'); | |
75 | |
76 setTimeout(function() { | |
77 if (chrome.hotwordPrivate.setAudioLoggingEnabled) | |
78 chrome.hotwordPrivate.setAudioLoggingEnabled(true, function() {}); | |
79 | |
80 if (chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled) { | |
81 chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled(true, | |
82 flow.advanceStep.bind(flow)); | |
83 } | |
84 }, 2000); | |
85 }); | |
86 } | |
87 } | |
88 | |
89 addTrainingEventListeners('speech-training'); | |
90 addTrainingEventListeners('hotword-only'); | |
82 }); | 91 }); |
OLD | NEW |