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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 */ | 247 */ |
248 function isRTL() { | 248 function isRTL() { |
249 return document.documentElement.dir == 'rtl'; | 249 return document.documentElement.dir == 'rtl'; |
250 } | 250 } |
251 | 251 |
252 /** | 252 /** |
253 * Get an element that's known to exist by its ID. We use this instead of just | 253 * Get an element that's known to exist by its ID. We use this instead of just |
254 * calling getElementById and not checking the result because this lets us | 254 * calling getElementById and not checking the result because this lets us |
255 * satisfy the JSCompiler type system. | 255 * satisfy the JSCompiler type system. |
256 * @param {string} id The identifier name. | 256 * @param {string} id The identifier name. |
257 * @return {!Element} the Element. | 257 * @return {!HTMLElement} the Element. |
258 */ | 258 */ |
259 function getRequiredElement(id) { | 259 function getRequiredElement(id) { |
260 var element = $(id); | 260 var element = $(id); |
261 assert(element, 'Missing required element: ' + id); | 261 assert(element, 'Missing required element: ' + id); |
Dan Beam
2014/10/01 01:25:57
why does the rest of this method exist now?
Vitaly Pavlenko
2014/10/01 03:07:32
Done.
| |
262 return /** @type {!Element} */(element); | 262 return assertInstanceof($(id), HTMLElement, |
263 'Missing required element: ' + id); | |
263 } | 264 } |
264 | 265 |
265 // Handle click on a link. If the link points to a chrome: or file: url, then | 266 // Handle click on a link. If the link points to a chrome: or file: url, then |
266 // call into the browser to do the navigation. | 267 // call into the browser to do the navigation. |
267 document.addEventListener('click', function(e) { | 268 document.addEventListener('click', function(e) { |
268 if (e.defaultPrevented) | 269 if (e.defaultPrevented) |
269 return; | 270 return; |
270 | 271 |
271 var el = e.target; | 272 var el = e.target; |
272 if (el.nodeType == Node.ELEMENT_NODE && | 273 if (el.nodeType == Node.ELEMENT_NODE && |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 * @param {number} maxLength The maximum length allowed for the string. | 433 * @param {number} maxLength The maximum length allowed for the string. |
433 * @return {string} The original string if its length does not exceed | 434 * @return {string} The original string if its length does not exceed |
434 * |maxLength|. Otherwise the first |maxLength| - 1 characters with '...' | 435 * |maxLength|. Otherwise the first |maxLength| - 1 characters with '...' |
435 * appended. | 436 * appended. |
436 */ | 437 */ |
437 function elide(original, maxLength) { | 438 function elide(original, maxLength) { |
438 if (original.length <= maxLength) | 439 if (original.length <= maxLength) |
439 return original; | 440 return original; |
440 return original.substring(0, maxLength - 1) + '\u2026'; | 441 return original.substring(0, maxLength - 1) + '\u2026'; |
441 } | 442 } |
OLD | NEW |