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

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

Issue 667933003: Ensure existence of queried elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make some parameters non-nullable. Created 6 years, 1 month 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
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/ui/progress_center_panel.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 }
OLDNEW
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/ui/progress_center_panel.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698