| 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 267  */ | 267  */ | 
| 268 function getRequiredElement(id) { | 268 function getRequiredElement(id) { | 
| 269   return assertInstanceof($(id), HTMLElement, | 269   return assertInstanceof($(id), HTMLElement, | 
| 270                           'Missing required element: ' + id); | 270                           'Missing required element: ' + id); | 
| 271 } | 271 } | 
| 272 | 272 | 
| 273 /** | 273 /** | 
| 274  * Query an element that's known to exist by a selector. We use this instead of | 274  * Query an element that's known to exist by a selector. We use this instead of | 
| 275  * just calling querySelector and not checking the result because this lets us | 275  * just calling querySelector and not checking the result because this lets us | 
| 276  * satisfy the JSCompiler type system. | 276  * satisfy the JSCompiler type system. | 
| 277  * @param {(!Document|!DocumentFragment|!Element)} context The context object |  | 
| 278  *     for querySelector. |  | 
| 279  * @param {string} selectors CSS selectors to query the element. | 277  * @param {string} selectors CSS selectors to query the element. | 
|  | 278  * @param {(!Document|!DocumentFragment|!Element)=} opt_context An optional | 
|  | 279  *     context object for querySelector. | 
| 280  * @return {!HTMLElement} the Element. | 280  * @return {!HTMLElement} the Element. | 
| 281  */ | 281  */ | 
| 282 function queryRequiredElement(context, selectors) { | 282 function queryRequiredElement(selectors, opt_context) { | 
| 283   var element = context.querySelector(selectors); | 283   var element = (opt_context || document).querySelector(selectors); | 
| 284   return assertInstanceof(element, HTMLElement, | 284   return assertInstanceof(element, HTMLElement, | 
| 285                           'Missing required element: ' + selectors); | 285                           'Missing required element: ' + selectors); | 
| 286 } | 286 } | 
| 287 | 287 | 
| 288 // Handle click on a link. If the link points to a chrome: or file: url, then | 288 // Handle click on a link. If the link points to a chrome: or file: url, then | 
| 289 // call into the browser to do the navigation. | 289 // call into the browser to do the navigation. | 
| 290 document.addEventListener('click', function(e) { | 290 document.addEventListener('click', function(e) { | 
| 291   if (e.defaultPrevented) | 291   if (e.defaultPrevented) | 
| 292     return; | 292     return; | 
| 293 | 293 | 
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 455  * @param {number} maxLength The maximum length allowed for the string. | 455  * @param {number} maxLength The maximum length allowed for the string. | 
| 456  * @return {string} The original string if its length does not exceed | 456  * @return {string} The original string if its length does not exceed | 
| 457  *     |maxLength|. Otherwise the first |maxLength| - 1 characters with '...' | 457  *     |maxLength|. Otherwise the first |maxLength| - 1 characters with '...' | 
| 458  *     appended. | 458  *     appended. | 
| 459  */ | 459  */ | 
| 460 function elide(original, maxLength) { | 460 function elide(original, maxLength) { | 
| 461   if (original.length <= maxLength) | 461   if (original.length <= maxLength) | 
| 462     return original; | 462     return original; | 
| 463   return original.substring(0, maxLength - 1) + '\u2026'; | 463   return original.substring(0, maxLength - 1) + '\u2026'; | 
| 464 } | 464 } | 
| OLD | NEW | 
|---|