Chromium Code Reviews| 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 && e.target.className.split(' '); |
| 13 for (var i = 0; i < closeButtons.length; ++i) { | 13 if (classes) { |
| 14 var closeButton = closeButtons[i]; | 14 for (var i = 0; i < classes.length; ++i) { |
| 15 closeButton.addEventListener('click', function(e) { | 15 if (classes[i] == 'close' || classes[i] == 'finish-button') { |
|
Dan Beam
2014/10/24 19:07:03
var classes = e.target.classList;
if (classes.cont
kcarattini
2014/10/25 03:47:57
Done.
| |
| 16 appWindow.close(); | 16 appWindow.close(); |
| 17 e.preventDefault(); | 17 e.preventDefault(); |
| 18 }); | 18 } |
| 19 } | 19 } |
| 20 } | |
| 21 }; | |
| 20 | 22 |
| 21 $('ah-cancel-button').addEventListener('click', function(e) { | 23 // TODO(kcarattini): Cancel training in NaCl module for ho- and st- |
| 22 appWindow.close(); | 24 // close and cancel buttons. |
| 23 e.preventDefault(); | 25 $('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 | 26 |
| 52 $('hw-agree-button').addEventListener('click', function(e) { | 27 $('hw-agree-button').addEventListener('click', function(e) { |
| 53 flow.advanceStep(); | 28 flow.advanceStep(); |
| 54 e.preventDefault(); | 29 e.preventDefault(); |
| 55 }); | 30 }); |
| 56 | 31 |
| 57 // TODO(kcarattini): Remove this once speech training is implemented. The | 32 $('settings-link').addEventListener('click', function(e) { |
| 58 // way to get to the next page will be to complete the speech training. | 33 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(); | 34 e.preventDefault(); |
| 68 }); | 35 }); |
| 69 | 36 |
| 70 // TODO(kcarattini): Remove this once speech training is implemented. The | 37 /** |
| 71 // way to get to the next page will be to complete the speech training. | 38 * Updates steps of the training UI. |
| 72 $('ho-training').addEventListener('click', function(e) { | 39 * @param {string} pagePrefix Prefix of the element ids for this page. |
| 73 if (chrome.hotwordPrivate.setAudioLoggingEnabled) | 40 * @param {Event} e The click event. |
| 74 chrome.hotwordPrivate.setAudioLoggingEnabled(true, function() {}); | 41 */ |
| 42 function doTraining(pagePrefix, e) { | |
| 43 // TODO(kcarattini): Update this to respond to a hotword trigger once | |
| 44 // speech training is implemented. | |
| 45 var steps = $(pagePrefix + '-training').querySelectorAll('.train'); | |
| 46 var index = 0; | |
|
Dan Beam
2014/10/24 19:07:03
var index = Math.min(0, Array.prototype.indexOf.ca
kcarattini
2014/10/25 03:47:56
Done.
| |
| 47 for (var i = 0; i < steps.length; ++i) { | |
| 48 if (steps[i] == e.currentTarget) | |
| 49 index = i; | |
| 50 } | |
| 75 | 51 |
| 76 if (chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled) { | 52 // TODO(kcarattini): Localize this string. |
| 77 chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled(true, | 53 steps[index].querySelector('.text').textContent = 'Recorded'; |
| 78 flow.advanceStep.bind(flow)); | 54 steps[index].classList.remove('listening'); |
| 55 steps[index].classList.add('recorded'); | |
| 56 | |
| 57 if (index != steps.length - 1) { | |
|
Dan Beam
2014/10/24 19:07:03
nit: why not if (steps[index + 1]) ?
kcarattini
2014/10/25 03:47:56
Done.
| |
| 58 steps[index + 1].classList.remove('not-started'); | |
| 59 steps[index + 1].classList.add('listening'); | |
| 79 } | 60 } |
| 80 e.preventDefault(); | 61 } |
| 81 }); | 62 |
| 63 /** | |
| 64 * Adds event listeners to the training UI. | |
| 65 * @param {string} pagePrefix Prefix of the element ids for this page. | |
| 66 */ | |
| 67 function addTrainingEventListeners(pagePrefix) { | |
| 68 // Loop only until the second to last step because the last step | |
| 69 // has different behavior. | |
|
Dan Beam
2014/10/24 19:07:03
indent off
kcarattini
2014/10/25 03:47:56
Done.
| |
| 70 var steps = $(pagePrefix + '-training').querySelectorAll('.train'); | |
| 71 for (var i = 0; i < steps.length - 1; ++i) { | |
| 72 steps[i].addEventListener('click', function(e) { | |
| 73 doTraining(pagePrefix, e); | |
| 74 e.preventDefault(); | |
| 75 }); | |
| 76 } | |
| 77 | |
| 78 steps[steps.length - 1].addEventListener('click', function(e) { | |
| 79 doTraining(pagePrefix, e); | |
| 80 | |
| 81 // Update the 'Cancel' button. | |
|
Dan Beam
2014/10/24 19:07:04
nit: just use the same event listener and detect t
kcarattini
2014/10/25 03:47:57
Done.
| |
| 82 var buttonElem = $(pagePrefix + '-cancel-button'); | |
| 83 // TODO(kcarattini): Localize this string. | |
| 84 buttonElem.textContent = 'Please wait ...'; | |
| 85 buttonElem.classList.add('grayed-out'); | |
| 86 buttonElem.classList.remove('finish-button'); | |
| 87 | |
| 88 setTimeout(function() { | |
| 89 if (chrome.hotwordPrivate.setAudioLoggingEnabled) | |
| 90 chrome.hotwordPrivate.setAudioLoggingEnabled(true, function() {}); | |
| 91 | |
| 92 if (chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled) { | |
| 93 chrome.hotwordPrivate.setHotwordAlwaysOnSearchEnabled(true, | |
| 94 flow.advanceStep.bind(flow)); | |
| 95 } | |
| 96 e.preventDefault(); | |
| 97 }, 2000); | |
| 98 }); | |
| 99 } | |
| 100 | |
| 101 addTrainingEventListeners('st'); | |
| 102 addTrainingEventListeners('ho'); | |
| 82 }); | 103 }); |
| OLD | NEW |