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 * The global object. | 8 * The global object. |
9 * @type {!Object} | 9 * @type {!Object} |
10 * @const | 10 * @const |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 374 |
375 /** | 375 /** |
376 * Alias for document.scrollLeft setter. | 376 * Alias for document.scrollLeft setter. |
377 * @param {!HTMLDocument} doc The document node where information will be | 377 * @param {!HTMLDocument} doc The document node where information will be |
378 * queried from. | 378 * queried from. |
379 * @param {number} value The target X scroll offset. | 379 * @param {number} value The target X scroll offset. |
380 */ | 380 */ |
381 function setScrollLeftForDocument(doc, value) { | 381 function setScrollLeftForDocument(doc, value) { |
382 doc.documentElement.scrollLeft = doc.body.scrollLeft = value; | 382 doc.documentElement.scrollLeft = doc.body.scrollLeft = value; |
383 } | 383 } |
| 384 |
| 385 /** |
| 386 * Replaces '&', '<', '>', '"', and ''' characters with their HTML encoding. |
| 387 * @param {string} original The original string. |
| 388 * @return {string} The string with all the characters mentioned above replaced. |
| 389 */ |
| 390 function HTMLEscape(original) { |
| 391 return original.replace(/&/g, '&') |
| 392 .replace(/</g, '<') |
| 393 .replace(/>/g, '>') |
| 394 .replace(/"/g, '"') |
| 395 .replace(/'/g, '''); |
| 396 } |
| 397 |
| 398 /** |
| 399 * Shortens the provided string (if necessary) to a string of length at most |
| 400 * |maxLength|. |
| 401 * @param {string} original The original string. |
| 402 * @param {number} maxLength The maximum length allowed for the string. |
| 403 * @return {string} The original string if its length does not exceed |
| 404 * |maxLength|. Otherwise the first |maxLength| - 3 characters with '...' |
| 405 * appended. |
| 406 */ |
| 407 function elide(original, maxLength) { |
| 408 if (original.length <= maxLength) |
| 409 return original; |
| 410 return original.substring(0, maxLength - 3) + '...'; |
| 411 } |
OLD | NEW |