Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(987)

Side by Side Diff: ui/webui/resources/js/util.js

Issue 1304883005: Make |context| passed to queryRequiredElement optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: asdf Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698