-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebInJSON.js
More file actions
46 lines (41 loc) · 1.42 KB
/
WebInJSON.js
File metadata and controls
46 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var elementCount = 0;
function addElement (child, parent) {
if (!child.type) return;
elementCount++;
console.log('child = ' + JSON.stringify(child));
console.log('element count = ' + elementCount);
if (child.style) {
var style = '';
child.style.forEach(function(css) {
style += css;
});
child.style = style;
}
var childElement;
if (child.id) {
childElement = '<' + child.type + ' id="' + child.id + '" ';
}
else {
childElement = '<' + child.type + ' id="' + elementCount + '" ';
}
if (child.style) childElement += 'style="' + style + '" ';
if (child.href) childElement += 'href="' + child.href + '" ';
if (child.src) childElement += 'src="' + child.src + '" ';
if (child.class) childElement += 'class="' + child.class + '" ';
if (child.width) childElement += 'width="' + child.width + '" ';
if (child.height) childElement += 'height="' + child.height + '" ';
childElement += '>';
if (child.text) childElement += child.text;
childElement += '</' + child.type + '>';
console.log('childElement = ' + childElement);
$(parent).append(childElement);
if (child.id) {
var parentId = $('#' + child.id);
}
else {
var parentId = $('#' + elementCount);
}
if (child.contents) child.contents.forEach (function(element) {
addElement(element, parentId);
});
}