summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/hotword_audio_verification/main.js
blob: 1adff67fa399bb9d4c5af4a74a4ab0dc50217924 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var appWindow = chrome.app.window.current();

document.addEventListener('DOMContentLoaded', function() {
  chrome.hotwordPrivate.getLocalizedStrings(function(strings) {
    loadTimeData.data = strings;
    i18nTemplate.process(document, loadTimeData);

    var flow = new Flow();
    flow.startFlow();

    var pressFunction = function(e) {
      // Only respond to 'Enter' key presses.
      if (e.type == 'keyup' && e.keyIdentifier != 'Enter')
        return;

      var classes = e.target.classList;
      if (classes.contains('close') || classes.contains('finish-button')) {
        flow.stopTraining();
        appWindow.close();
        e.preventDefault();
      }
      if (classes.contains('retry-button')) {
        flow.handleRetry();
        e.preventDefault();
      }
    };

    $('steps').addEventListener('click', pressFunction);
    $('steps').addEventListener('keyup', pressFunction);

    $('audio-history-agree').addEventListener('click', function(e) {
      flow.enableAudioHistory();
      e.preventDefault();
    });

    $('hotword-start').addEventListener('click', function(e) {
      flow.advanceStep();
      e.preventDefault();
    });

    $('settings-link').addEventListener('click', function(e) {
      chrome.browser.openTab({'url': 'chrome://settings'}, function() {});
      e.preventDefault();
    });
  });
});