-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
67 lines (47 loc) · 1.38 KB
/
script.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
let ero = ""
let t = null
// setTimeout(ero , 1000);
// function ero() {
// if (error == 0) {
// error += 1
// alert(`Error!/n Cannot load sam element`)
// }
// else {
// alert(`Error!/n Cannot load all elements`)
// }
function loadComponent(name) {
let link = document.createElement("link")
link.rel = "stylesheet"
link.href = `/${name}/${name}.css`
link.addEventListener(`error`, function () {
ero += `ERROR\n Cannot load ${name}.css\n`
clearTimeout(t)
t = setTimeout(showError, 1000)
})
console.log(link)
document.head.appendChild(link)
let script = document.createElement("script")
console.log(script)
script.addEventListener(`error`, function () {
ero += `ERROR\n Cannot load ${name}.js\n`
clearTimeout(t)
t = setTimeout(showError, 1000)
}
)
function ucFirst(name) {
return name[0].toUpperCase() + name.slice(1);
}
script.src = `/${name}/${ucFirst(name)}.js`
console.log(script)
document.body.appendChild(script)
}
function showError() {
alert( ero)
}
// setTimeout(showError,2000)
loadComponent("user")
window.onload = function () {
console.log("ok")
let user1 = new User("Jeck", "images/foto.jpg", "M", "UK", "1999.05.22")
user1.render(document.body)//юзер отрендариться в документе
}