OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * Alias for document.getElementById. | |
7 * @param {string} id The ID of the element to find. | |
8 * @return {HTMLElement} The found element or null if not found. | |
9 */ | |
10 function $(id) { | |
11 return document.getElementById(id); | |
12 } | |
13 | |
14 /** | |
15 * Creates a new URL which is the old URL with a GET param of key=value. | |
16 * Copied from ui/webui/resources/js/util.js. | |
17 * @param {string} url The base URL. There is not sanity checking on the URL so | |
18 * it must be passed in a proper format. | |
19 * @param {string} key The key of the param. | |
20 * @param {string} value The value of the param. | |
21 * @return {string} The new URL. | |
22 */ | |
23 function appendParam(url, key, value) { | |
24 var param = encodeURIComponent(key) + '=' + encodeURIComponent(value); | |
25 | |
26 if (url.indexOf('?') == -1) | |
27 return url + '?' + param; | |
28 return url + '&' + param; | |
29 } | |
30 | |
31 /** | |
32 * Creates a new URL by striping all query parameters. | |
33 * @param {string} url The original URL. | |
34 * @return {string} The new URL with all query parameters stripped. | |
35 */ | |
36 function stripParams(url) { | |
37 return url.substring(0, url.indexOf('?')) || url; | |
38 } | |
39 | |
40 /** | |
41 * Extract domain name from an URL. | |
42 * @param {string} url An URL string. | |
43 * @return {string} The host name of the URL. | |
44 */ | |
45 function extractDomain(url) { | |
46 var a = document.createElement('a'); | |
47 a.href = url; | |
48 return a.hostname; | |
49 } | |
OLD | NEW |