OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <include src="assert.js"> | 5 <include src="assert.js"> |
6 | 6 |
7 /** | 7 /** |
8 * Alias for document.getElementById. | 8 * Alias for document.getElementById. |
9 * @param {string} id The ID of the element to find. | 9 * @param {string} id The ID of the element to find. |
10 * @return {HTMLElement} The found element or null if not found. | 10 * @return {HTMLElement} The found element or null if not found. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 161 |
162 var newQuery = ''; | 162 var newQuery = ''; |
163 for (var q in query) { | 163 for (var q in query) { |
164 newQuery += (newQuery ? '&' : '?') + q + '=' + query[q]; | 164 newQuery += (newQuery ? '&' : '?') + q + '=' + query[q]; |
165 } | 165 } |
166 | 166 |
167 return location.origin + location.pathname + newQuery + location.hash; | 167 return location.origin + location.pathname + newQuery + location.hash; |
168 } | 168 } |
169 | 169 |
170 /** | 170 /** |
171 * @param {Node} el An element to search for ancestors with |className|. | 171 * @param {Element} el An element to search for ancestors with |className|. |
172 * @param {string} className A class to search for. | 172 * @param {string} className A class to search for. |
173 * @return {Node} A node with class of |className| or null if none is found. | 173 * @return {Element} A node with class of |className| or null if none is found. |
174 */ | 174 */ |
175 function findAncestorByClass(el, className) { | 175 function findAncestorByClass(el, className) { |
176 return findAncestor(el, function(el) { | 176 return /** @type {Element} */(findAncestor(el, function(el) { |
177 return el.classList && el.classList.contains(className); | 177 return el.classList && el.classList.contains(className); |
178 }); | 178 })); |
179 } | 179 } |
180 | 180 |
181 /** | 181 /** |
182 * Return the first ancestor for which the {@code predicate} returns true. | 182 * Return the first ancestor for which the {@code predicate} returns true. |
183 * @param {Node} node The node to check. | 183 * @param {Node} node The node to check. |
184 * @param {function(Node):boolean} predicate The function that tests the | 184 * @param {function(Node):boolean} predicate The function that tests the |
185 * nodes. | 185 * nodes. |
186 * @return {Node} The found ancestor or null if not found. | 186 * @return {Node} The found ancestor or null if not found. |
187 */ | 187 */ |
188 function findAncestor(node, predicate) { | 188 function findAncestor(node, predicate) { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 * @param {number} maxLength The maximum length allowed for the string. | 432 * @param {number} maxLength The maximum length allowed for the string. |
433 * @return {string} The original string if its length does not exceed | 433 * @return {string} The original string if its length does not exceed |
434 * |maxLength|. Otherwise the first |maxLength| - 1 characters with '...' | 434 * |maxLength|. Otherwise the first |maxLength| - 1 characters with '...' |
435 * appended. | 435 * appended. |
436 */ | 436 */ |
437 function elide(original, maxLength) { | 437 function elide(original, maxLength) { |
438 if (original.length <= maxLength) | 438 if (original.length <= maxLength) |
439 return original; | 439 return original; |
440 return original.substring(0, maxLength - 1) + '\u2026'; | 440 return original.substring(0, maxLength - 1) + '\u2026'; |
441 } | 441 } |
OLD | NEW |