- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / sync_file_system_internals / utils.js
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
3 // found in the LICENSE file.
4
5 /**
6  * Creates an element named |elementName| containing the content |text|.
7  * @param {string} elementName Name of the new element to be created.
8  * @param {string} text Text to be contained in the new element.
9  * @param {Object} opt_attributes Optional attribute dictionary for the element.
10  * @return {HTMLElement} The newly created HTML element.
11  */
12 function createElementFromText(elementName, text, opt_attributes) {
13   var element = document.createElement(elementName);
14   element.appendChild(document.createTextNode(text));
15   if (opt_attributes) {
16     for (var key in opt_attributes)
17       element.setAttribute(key, opt_attributes[key]);
18   }
19   return element;
20 }
21
22 /**
23  * Creates an element with |tagName| containing the content |dict|.
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
26  * element.
27  * @return {HTMLElement} The newly created HTML element.
28  */
29 function createElementFromDictionary(elementName, dict) {
30   var element = document.createElement(elementName);
31   for (var key in dict) {
32     element.appendChild(document.createTextNode(key + ': ' + dict[key]));
33     element.appendChild(document.createElement('br'));
34   }
35   return element;
36 }