| 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 /** | 5 /** |
| 6 * @fileoverview Holds information about a braille table. | 6 * @fileoverview Holds information about a braille table. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 goog.provide('cvox.BrailleTable'); | 9 goog.provide('cvox.BrailleTable'); |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * @const {string} | 25 * @const {string} |
| 26 */ | 26 */ |
| 27 cvox.BrailleTable.TABLE_PATH = 'chromevox/background/braille/tables.json'; | 27 cvox.BrailleTable.TABLE_PATH = 'chromevox/background/braille/tables.json'; |
| 28 | 28 |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * Retrieves a list of all available braille tables. | 31 * Retrieves a list of all available braille tables. |
| 32 * @param {function(!Array.<cvox.BrailleTable.Table>)} callback | 32 * @param {function(!Array.<cvox.BrailleTable.Table>)} callback |
| 33 * Called asynchronously with an array of tables. |
| 33 */ | 34 */ |
| 34 cvox.BrailleTable.getAll = function(callback) { | 35 cvox.BrailleTable.getAll = function(callback) { |
| 35 var url = chrome.extension.getURL(cvox.BrailleTable.TABLE_PATH); | 36 var url = chrome.extension.getURL(cvox.BrailleTable.TABLE_PATH); |
| 36 if (!url) { | 37 if (!url) { |
| 37 throw 'Invalid path: ' + cvox.BrailleTable.TABLE_PATH; | 38 throw 'Invalid path: ' + cvox.BrailleTable.TABLE_PATH; |
| 38 } | 39 } |
| 39 | 40 |
| 40 var xhr = new XMLHttpRequest(); | 41 var xhr = new XMLHttpRequest(); |
| 41 xhr.open('GET', url, true); | 42 xhr.open('GET', url, true); |
| 42 xhr.onreadystatechange = function() { | 43 xhr.onreadystatechange = function() { |
| 43 if (xhr.readyState == 4) { | 44 if (xhr.readyState == 4) { |
| 44 if (xhr.status == 200) { | 45 if (xhr.status == 200) { |
| 45 callback(/** @type {!Array.<cvox.BrailleTable.Table>} */ ( | 46 callback(/** @type {!Array.<cvox.BrailleTable.Table>} */ ( |
| 46 JSON.parse(xhr.responseText))); | 47 JSON.parse(xhr.responseText))); |
| 47 } | 48 } |
| 48 } | 49 } |
| 49 }; | 50 }; |
| 50 xhr.send(); | 51 xhr.send(); |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 | 54 |
| 54 /** | 55 /** |
| 55 * Finds a table in a list of tables by id. | 56 * Finds a table in a list of tables by id. |
| 56 * @param {!Array.<cvox.BrailleTable.Table>} tables tables to search in. | 57 * @param {!Array.<cvox.BrailleTable.Table>} tables tables to search in. |
| 57 * @param {string} id id of table to find. | 58 * @param {string} id id of table to find. |
| 58 * @return {cvox.BrailleTable.Table} | 59 * @return {cvox.BrailleTable.Table} The found table, or null if not found. |
| 59 */ | 60 */ |
| 60 cvox.BrailleTable.forId = function(tables, id) { | 61 cvox.BrailleTable.forId = function(tables, id) { |
| 61 return tables.filter(function(table) { return table.id === id })[0] || null; | 62 return tables.filter(function(table) { return table.id === id })[0] || null; |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 | 65 |
| 65 /** | 66 /** |
| 66 * Returns an uncontracted braille table corresponding to another, possibly | 67 * Returns an uncontracted braille table corresponding to another, possibly |
| 67 * contracted, table. If {@code table} is the lowest-grade table for its | 68 * contracted, table. If {@code table} is the lowest-grade table for its |
| 68 * locale and dot count, {@code table} itself is returned. | 69 * locale and dot count, {@code table} itself is returned. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 84 current.dots === candidate.dots && | 85 current.dots === candidate.dots && |
| 85 goog.isDef(current.grade) && | 86 goog.isDef(current.grade) && |
| 86 goog.isDef(candidate.grade) && | 87 goog.isDef(candidate.grade) && |
| 87 candidate.grade < current.grade) { | 88 candidate.grade < current.grade) { |
| 88 return candidate; | 89 return candidate; |
| 89 } | 90 } |
| 90 return current; | 91 return current; |
| 91 } | 92 } |
| 92 return tables.reduce(mostUncontractedOf, table); | 93 return tables.reduce(mostUncontractedOf, table); |
| 93 }; | 94 }; |
| OLD | NEW |