OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview ChromeVox panel. |
| 7 * |
| 8 */ |
| 9 |
| 10 goog.provide('cvox.Panel'); |
| 11 |
| 12 goog.require('cvox.ChromeVox'); |
| 13 goog.require('cvox.ExtensionBridge'); |
| 14 goog.require('cvox.Msgs'); |
| 15 goog.require('cvox.PanelCommand'); |
| 16 |
| 17 /** |
| 18 * Class to manage the options page. |
| 19 * @constructor |
| 20 */ |
| 21 cvox.Panel = function() { |
| 22 }; |
| 23 |
| 24 /** |
| 25 * Initialize the panel. |
| 26 */ |
| 27 cvox.Panel.init = function() { |
| 28 cvox.ChromeVox.msgs = new cvox.Msgs(); |
| 29 |
| 30 /** @type {Element} */ |
| 31 this.speechContainer_ = $('speech-container'); |
| 32 |
| 33 /** @type {Element} */ |
| 34 this.speechElement_ = $('speech'); |
| 35 |
| 36 /** @type {Element} */ |
| 37 this.brailleContainer_ = $('braille-container'); |
| 38 |
| 39 /** @type {Element} */ |
| 40 this.brailleTextElement_ = $('braille-text'); |
| 41 |
| 42 /** @type {Element} */ |
| 43 this.brailleCellsElement_ = $('braille-cells'); |
| 44 |
| 45 cvox.Panel.updateFromPrefs(); |
| 46 window.addEventListener('storage', function(event) { |
| 47 if (event.key == 'brailleCaptions') { |
| 48 cvox.Panel.updateFromPrefs(); |
| 49 } |
| 50 }, false); |
| 51 |
| 52 window.addEventListener('message', function(message) { |
| 53 var command = JSON.parse(message.data); |
| 54 cvox.Panel.exec(/** @type {cvox.PanelCommand} */(command)); |
| 55 }, false); |
| 56 |
| 57 $('options').addEventListener('click', cvox.Panel.onOptions, false); |
| 58 $('close').addEventListener('click', cvox.Panel.onClose, false); |
| 59 }; |
| 60 |
| 61 /** |
| 62 * Update the display based on prefs. |
| 63 */ |
| 64 cvox.Panel.updateFromPrefs = function() { |
| 65 if (localStorage['brailleCaptions'] === String(true)) { |
| 66 this.speechContainer_.style.visibility = 'hidden'; |
| 67 this.brailleContainer_.style.visibility = 'visible'; |
| 68 } else { |
| 69 this.speechContainer_.style.visibility = 'visible'; |
| 70 this.brailleContainer_.style.visibility = 'hidden'; |
| 71 } |
| 72 }; |
| 73 |
| 74 /** |
| 75 * Execute a command to update the panel. |
| 76 * |
| 77 * @param {cvox.PanelCommand} command The command to execute. |
| 78 */ |
| 79 cvox.Panel.exec = function(command) { |
| 80 switch (command.type) { |
| 81 case cvox.PanelCommandType.CLEAR_SPEECH: |
| 82 this.speechElement_.innerHTML = ''; |
| 83 break; |
| 84 case cvox.PanelCommandType.ADD_NORMAL_SPEECH: |
| 85 if (this.speechElement_.innerHTML != '') { |
| 86 this.speechElement_.innerHTML += ' '; |
| 87 } |
| 88 this.speechElement_.innerHTML += '<span class="usertext">' + |
| 89 command.data + |
| 90 '</span>'; |
| 91 break; |
| 92 case cvox.PanelCommandType.ADD_ANNOTATION_SPEECH: |
| 93 if (this.speechElement_.innerHTML != '') { |
| 94 this.speechElement_.innerHTML += ' '; |
| 95 } |
| 96 this.speechElement_.innerHTML += command.data; |
| 97 break; |
| 98 case cvox.PanelCommandType.UPDATE_BRAILLE_TEXT: |
| 99 this.brailleTextElement_.textContent = command.data; |
| 100 break; |
| 101 case cvox.PanelCommandType.UPDATE_BRAILLE_CELLS: |
| 102 this.brailleCellsElement_.textContent = command.data; |
| 103 break; |
| 104 } |
| 105 }; |
| 106 |
| 107 /** |
| 108 * Open the ChromeVox Options. |
| 109 */ |
| 110 cvox.Panel.onOptions = function() { |
| 111 }; |
| 112 |
| 113 /** |
| 114 * Exit ChromeVox. |
| 115 */ |
| 116 cvox.Panel.onClose = function() { |
| 117 }; |
| 118 |
| 119 window.addEventListener('load', function() { |
| 120 cvox.Panel.init(); |
| 121 }, false); |
OLD | NEW |