-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoothpaste_htmlToJson.js
More file actions
93 lines (83 loc) · 3.28 KB
/
toothpaste_htmlToJson.js
File metadata and controls
93 lines (83 loc) · 3.28 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var fct = {
convertToNode: function(element) {
var docNode = "";
if (typeof element === "string") {
if (window.DOMParser) {
var parser = new DOMParser();
docNode = parser.parseFromString(element,"text/xml");
} else { // Microsoft strikes again
docNode = new ActiveXObject("Microsoft.XMLDOM");
docNode.async = false;
docNode.loadXML(element);
}
element = docNode.firstChild;
}
return element;
},
convertTemplate: function(idElement) {
var template = document.getElementById(idElement);
var tr = template.rows;
var wrapperTpl = {
"type":"container",
"is_container": true,
"tplContainer":"list",
"columns":[]
};
var arrWrapper = [];
var td = tr[0].cells;
var childsTd = td[0].children;
for(var c=0; c<childsTd.length; c++) {
var tableChildTds = childsTd[c].children[0];
var tdsTableChildTds = tableChildTds.rows[0].cells[0];
var widthtable = getComputedStyle(tdsTableChildTds).width.split("px");
var divPadding = getComputedStyle(tdsTableChildTds.children[0]).padding.split("px");
var objTds = {
"type": "container",
"is_container": true,
"tplContainer": "listNoDrop",
"columns": [],
"cellClasses": [],
"divClass":childsTd[c].className,
"classContainer": tableChildTds.className,
"widthTable": widthtable[0],
"divPadding": divPadding[0]
};
//console.log(childsTd[c]);
for(var d = 0; d < tdsTableChildTds.children.length; d++) {
var childs = tdsTableChildTds.children[d];
// var item = {
// "type": "container"
// "is_container": true,
// "tplContainer": "listNoDrop",
// }
var arrTds = [];
//var getCellsClasses = childs.getAttribute("class");
var getCellsClasses = childs.getAttribute("class");
//arrTds.divCellClass = childs.
for(var i = 0; i < childs.children.length; i++) {
var html = childs.children[i].outerHTML;
var item = {
"type": "item",
"tdClass":childs.children[i].className,
"html":html,
"editor_conf": childs.children[i].getAttribute('data-conf')
};
arrTds.push(item);
arrTds.cellClasses = getCellsClasses;
}
objTds.cellClasses.push(getCellsClasses);
objTds.columns.push(arrTds);
}
arrWrapper.push(objTds);
}
//wrapperTpl['columns'].push(arrWrapper);
return arrWrapper;
},
inlineCssToothpaste: function(idElement) {
var style = document.getElementById(idElement);
style = style.innerHTML;
style = style.replace(/(\r\n|\n|\r)/gm,"");
style = style.replace(/\s+/g," ");
return style;
}
};