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.
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.
11 return document
.getElementById(id
);
15 * Extract query params from given search string of an URL.
16 * @param {string} search The search portion of an URL to extract params.
17 * @return {Object} The key value pairs of the extracted params.
19 function getUrlSearchParams(search
) {
24 search
= search
.substring(1);
25 var pairs
= search
.split('&');
26 for (var i
= 0; i
< pairs
.length
; ++i
) {
27 var pair
= pairs
[i
].split('=');
28 if (pair
.length
== 2) {
29 params
[pair
[0]] = decodeURIComponent(pair
[1]);
40 * Creates a new URL which is the old URL with a GET param of key=value.
41 * Copied from ui/webui/resources/js/util.js.
42 * @param {string} url The base URL. There is not sanity checking on the URL so
43 * it must be passed in a proper format.
44 * @param {string} key The key of the param.
45 * @param {string} value The value of the param.
46 * @return {string} The new URL.
48 function appendParam(url
, key
, value
) {
49 var param
= encodeURIComponent(key
) + '=' + encodeURIComponent(value
);
51 if (url
.indexOf('?') == -1)
52 return url
+ '?' + param
;
53 return url
+ '&' + param
;
57 * Creates a new URL by striping all query parameters.
58 * @param {string} url The original URL.
59 * @return {string} The new URL with all query parameters stripped.
61 function stripParams(url
) {
62 return url
.substring(0, url
.indexOf('?')) || url
;
66 * Extract domain name from an URL.
67 * @param {string} url An URL string.
68 * @return {string} The host name of the URL.
70 function extractDomain(url
) {
71 var a
= document
.createElement('a');