-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
87 lines (84 loc) · 2.08 KB
/
index.js
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
class FallView {
constructor({ root, debug = false, data = {} }) {
this.root = root;
this.app = document.querySelector(root);
this.elements = this.brakeElements(
this.isolateElements(this.app.innerHTML)
);
this.data = data;
this.html = this.app.innerHTML;
debug ? this.log() : "";
//this.elements = Array.from(this.app.children);
}
log() {
console.group("app");
console.log(this);
console.groupCollapsed("IsolateElements2");
console.log(this.isolateElements2(this.app.innerHTML));
console.groupEnd();
}
isolateElements() {
let tests = ["A", "B"];
for (test in tests) {
test = `isolateElements${test}()`;
}
throw new Error(`Use Isolate Element Tests: ${tests.join("\n")}`);
}
isolateElementsA(root) {
return root
.replace(new RegExp(/\n/, "g"), "!")
.replace(new RegExp(/<|>|\s/, "g"), "")
.split("!");
}
isolateElementsB(root) {
return root
.replace(new RegExp(/\n/, "g"), "!")
.replace(/\t/g, "")
.replace(/<\//g, "!")
.replace(/>/g, "!")
.split("!")
.filter(type => (type != "" ? type : ""));
}
brakeElements(arr) {
let out = [];
for (let i of arr) {
out.push(i.split("/")[0]);
}
return out.filter(type => (type != "" ? type : ""));
}
getTemplate(element) {
let temp = `template.${element}`;
return document.querySelector(temp).innerHTML;
}
replaceElement(element) {
app.querySelector(element).outerHTML = globalComponents[element];
}
templatify() {
let html = this.html;
let params = this.data;
let names = Object.keys(params);
let vals = Object.values(params);
return new Function(...names, `return \`${html}\`;`)(...vals);
}
}
var compArr = [];
var globalComponents = {};
// console.log(elements);
// for (let element of elements) {
// // let element = getElement(element)
// globalComponents[element] = getTemplate(element).replace(
// new RegExp(/\s/, "g"),
// ""
// );
// }
// console.log(globalComponents);
// function com() {
// compArr = Array.from(app.children);
// }
// var app = new FallView({
// root: ".app",
// debug: true,
// data: {
// content: "This is some content",
// },
// });