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 Utility functions for semantic tree computations. | 6 * @fileoverview Utility functions for semantic tree computations. |
7 */ | 7 */ |
8 | 8 |
9 goog.provide('cvox.SemanticUtil'); | 9 goog.provide('cvox.SemanticUtil'); |
10 | 10 |
11 | 11 |
12 /** | 12 /** |
13 * @constructor | 13 * @constructor |
14 */ | 14 */ |
15 cvox.SemanticUtil = function() { }; | 15 cvox.SemanticUtil = function() {}; |
16 | 16 |
17 | 17 |
18 /** | 18 /** |
19 * Merges keys of objects into an array. | 19 * Merges keys of objects into an array. |
20 * @param {...Object<string>} objects Optional objects. | 20 * @param {...Object<string>} objects Optional objects. |
21 * @return {Array<string>} Array of all keys of the objects. | 21 * @return {Array<string>} Array of all keys of the objects. |
22 */ | 22 */ |
23 cvox.SemanticUtil.objectsToKeys = function(objects) { | 23 cvox.SemanticUtil.objectsToKeys = function(objects) { |
24 objects = Array.prototype.slice.call(arguments, 0); | 24 objects = Array.prototype.slice.call(arguments, 0); |
25 var keys = []; | 25 var keys = []; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 * ignored if they have empty children. | 118 * ignored if they have empty children. |
119 * Observe that this is currently not recursive, i.e. will not take care of | 119 * Observe that this is currently not recursive, i.e. will not take care of |
120 * pathological cases, where content is hidden in incorrectly used tags! | 120 * pathological cases, where content is hidden in incorrectly used tags! |
121 * @param {Array<Element>} nodes The node list to be cleaned. | 121 * @param {Array<Element>} nodes The node list to be cleaned. |
122 * @return {Array<Element>} The cleansed list. | 122 * @return {Array<Element>} The cleansed list. |
123 */ | 123 */ |
124 cvox.SemanticUtil.purgeNodes = function(nodes) { | 124 cvox.SemanticUtil.purgeNodes = function(nodes) { |
125 var nodeArray = []; | 125 var nodeArray = []; |
126 for (var i = 0, node; node = nodes[i]; i++) { | 126 for (var i = 0, node; node = nodes[i]; i++) { |
127 var tagName = cvox.SemanticUtil.tagName(node); | 127 var tagName = cvox.SemanticUtil.tagName(node); |
128 if (cvox.SemanticUtil.IGNORETAGS.indexOf(tagName) != -1) continue; | 128 if (cvox.SemanticUtil.IGNORETAGS.indexOf(tagName) != -1) |
| 129 continue; |
129 if (cvox.SemanticUtil.EMPTYTAGS.indexOf(tagName) != -1 && | 130 if (cvox.SemanticUtil.EMPTYTAGS.indexOf(tagName) != -1 && |
130 node.childNodes.length == 0) | 131 node.childNodes.length == 0) |
131 continue; | 132 continue; |
132 nodeArray.push(node); | 133 nodeArray.push(node); |
133 } | 134 } |
134 return nodeArray; | 135 return nodeArray; |
135 }; | 136 }; |
OLD | NEW |