OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 /** | 5 /** |
6 * Creates an element named |elementName| containing the content |text|. | 6 * Creates an element named |elementName| containing the content |text|. |
7 * @param {string} elementName Name of the new element to be created. | 7 * @param {string} elementName Name of the new element to be created. |
8 * @param {string} text Text to be contained in the new element. | 8 * @param {string} text Text to be contained in the new element. |
9 * @param {Object} opt_attributes Optional attribute dictionary for the element. | 9 * @param {Object} opt_attributes Optional attribute dictionary for the element. |
10 * @return {HTMLElement} The newly created HTML element. | 10 * @return {HTMLElement} The newly created HTML element. |
11 */ | 11 */ |
12 function createElementFromText(elementName, text, opt_attributes) { | 12 function createElementFromText(elementName, text, opt_attributes) { |
13 var element = document.createElement(elementName); | 13 var element = document.createElement(elementName); |
14 element.appendChild(document.createTextNode(text)); | 14 element.appendChild(document.createTextNode(text)); |
15 if (opt_attributes) { | 15 if (opt_attributes) { |
16 for (var key in opt_attributes) | 16 for (var key in opt_attributes) |
17 element.setAttribute(key, opt_attributes[key]); | 17 element.setAttribute(key, opt_attributes[key]); |
18 } | 18 } |
19 return element; | 19 return element; |
20 } | 20 } |
21 | 21 |
22 /** | 22 /** |
23 * Creates an element with |tagName| containing the content |dict|. | 23 * Creates an element with |tagName| containing the content |dict|. |
24 * @param {string} elementName Name of the new element to be created. | 24 * @param {string} elementName Name of the new element to be created. |
25 * @param {Object.<string, string>} dict Dictionary to be contained in the new | 25 * @param {Object<string, string>} dict Dictionary to be contained in the new |
26 * element. | 26 * element. |
27 * @return {HTMLElement} The newly created HTML element. | 27 * @return {HTMLElement} The newly created HTML element. |
28 */ | 28 */ |
29 function createElementFromDictionary(elementName, dict) { | 29 function createElementFromDictionary(elementName, dict) { |
30 var element = document.createElement(elementName); | 30 var element = document.createElement(elementName); |
31 for (var key in dict) { | 31 for (var key in dict) { |
32 element.appendChild(document.createTextNode(key + ': ' + dict[key])); | 32 element.appendChild(document.createTextNode(key + ': ' + dict[key])); |
33 element.appendChild(document.createElement('br')); | 33 element.appendChild(document.createElement('br')); |
34 } | 34 } |
35 return element; | 35 return element; |
36 } | 36 } |
OLD | NEW |