| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 {!HTMLElement} the Element. | 257 * @return {!HTMLElement} the Element. |
| 258 */ | 258 */ |
| 259 function getRequiredElement(id) { | 259 function getRequiredElement(id) { |
| 260 return assertInstanceof($(id), HTMLElement, | 260 return assertInstanceof($(id), HTMLElement, |
| 261 'Missing required element: ' + id); | 261 'Missing required element: ' + id); |
| 262 } | 262 } |
| 263 | 263 |
| 264 /** |
| 265 * Query an element that's known to exist by a selector. We use this instead of |
| 266 * just calling querySelector and not checking the result because this lets us |
| 267 * satisfy the JSCompiler type system. |
| 268 * @param {(!Document|!DocumentFragment|!Element)} context The context object |
| 269 * for querySelector. |
| 270 * @param {string} selectors CSS selectors to query the element. |
| 271 * @return {!HTMLElement} the Element. |
| 272 */ |
| 273 function queryRequiredElement(context, selectors) { |
| 274 var element = context.querySelector(selectors); |
| 275 return assertInstanceof(element, HTMLElement, |
| 276 'Missing required element: ' + selectors); |
| 277 } |
| 278 |
| 264 // Handle click on a link. If the link points to a chrome: or file: url, then | 279 // Handle click on a link. If the link points to a chrome: or file: url, then |
| 265 // call into the browser to do the navigation. | 280 // call into the browser to do the navigation. |
| 266 document.addEventListener('click', function(e) { | 281 document.addEventListener('click', function(e) { |
| 267 if (e.defaultPrevented) | 282 if (e.defaultPrevented) |
| 268 return; | 283 return; |
| 269 | 284 |
| 270 var el = e.target; | 285 var el = e.target; |
| 271 if (el.nodeType == Node.ELEMENT_NODE && | 286 if (el.nodeType == Node.ELEMENT_NODE && |
| 272 el.webkitMatchesSelector('A, A *')) { | 287 el.webkitMatchesSelector('A, A *')) { |
| 273 while (el.tagName != 'A') { | 288 while (el.tagName != 'A') { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 * @param {number} maxLength The maximum length allowed for the string. | 446 * @param {number} maxLength The maximum length allowed for the string. |
| 432 * @return {string} The original string if its length does not exceed | 447 * @return {string} The original string if its length does not exceed |
| 433 * |maxLength|. Otherwise the first |maxLength| - 1 characters with '...' | 448 * |maxLength|. Otherwise the first |maxLength| - 1 characters with '...' |
| 434 * appended. | 449 * appended. |
| 435 */ | 450 */ |
| 436 function elide(original, maxLength) { | 451 function elide(original, maxLength) { |
| 437 if (original.length <= maxLength) | 452 if (original.length <= maxLength) |
| 438 return original; | 453 return original; |
| 439 return original.substring(0, maxLength - 1) + '\u2026'; | 454 return original.substring(0, maxLength - 1) + '\u2026'; |
| 440 } | 455 } |
| OLD | NEW |