-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
85 lines (55 loc) · 1.93 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
let idIndex = 2;
function DomElementWithId(element, type, innerHTML) {
let _element = document.createElement(element ? element : 'div');
_element.id = idIndex++;
type ? _element.type = type : null;
innerHTML ? _element.innerHTML = innerHTML : null;
return {
get $element() {
return _element;
},
set $element(element) {
let id = _element.id;
_element = document.createElement(element);
_element.id = id;
},
get $type() {
return _element.type;
},
set $type(type) {
_element.type = type;
},
get $innerHTML() {
return _element.innerHTML;
},
set $innerHTML(innerHTML) {
_element.innerHTML = innerHTML
}
};
};
function Post(comment) {
let postBlock = new DomElementWithId('div');
let replyInput = new DomElementWithId('input', 'text');
let replySubmit = new DomElementWithId('button', null ,'Reply');
let wall = new DomElementWithId('div');
replySubmit.$element.onclick = function() {
let reply = new DomElementWithId('h3', null, replyInput.$element.value);
replyInput.$element.value = null;
wall.$element.prepend(new Post(reply.$element).$element);
};
postBlock.$element.append(comment);
postBlock.$element.append(replyInput.$element);
postBlock.$element.append(replySubmit.$element);
postBlock.$element.append(wall.$element);
postBlock.$element.setAttribute('class', 'COLOR_'+getRandomInt(6))
return postBlock;
};
function createPost() {
let postInputField = document.getElementById(0);
let post = new DomElementWithId('h2', null, postInputField.value);
postInputField.value = null;
document.getElementById(1).prepend(new Post(post.$element).$element);
};
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}