-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmartboxes.js
103 lines (82 loc) · 2.3 KB
/
smartboxes.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
class SmartBox {
Box
constructor(what, inner) {
this.Box = document.createElement(what)
this.Box.innerHTML = inner
this.Box.className = 'oo' + this.Box.tagName
}
SetClassName(name) {
this.Box.className = name
}
}
class StaticBox extends SmartBox {
constructor(what, inner) {
super(what, inner)
return this.Box
}
}
class ActionBox extends SmartBox {
constructor(what, inner, action) {
super(what, inner)
this.Box.onclick = action
return this.Box
}
}
class UpDownBox extends SmartBox {
constructor(inner, Action) {
super('button', inner)
this.Box.onclick = Action
this.Box.style.borderRadius = "90%"
return this.Box
}
}
class NumberBox extends SmartBox {
Number
constructor(what, number) {
super(what, number)
this.Number = number
Object.assign(this.Box,
{
Up: () => {
this.Number++
this.Box.innerHTML = this.Number
}
},
{
Down: () => {
this.Number--
this.Box.innerHTML = this.Number
}
}
)
return this.Box
}
}
function AttachTo(where, ...what) {
const Where = document.querySelector(where)
what.forEach((w) => { Where.append(w) })
}
class CounterRow {
static instances
static sum
static average
count = 0
div = document.createElement('div')
button = document.createElement('button')
text = document.createElement('p')
clicks = document.createElement('p')
average = document.createElement('p')
constructor( name ) {
this.text.innerHTML = count
this.button.innerHTML = name
this.button.onclick = () => {
count++
CounterRow.sum += this.count
this.text.innerHTML = count
}
this.div.className = 'counterrow'
this.div.append( this.text, this.button, this.clicks, this.average )
CounterRow.instances++
return this.div
}
}