-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorABC.js
More file actions
64 lines (50 loc) · 1.79 KB
/
ColorABC.js
File metadata and controls
64 lines (50 loc) · 1.79 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
function ColorABC() {
};
//todo: fix method - somtetimes works incorrectly
ColorABC.prototype.getColor = function() {
var color = Math.floor(Math.random() * 0xFFFFFF).toString(16);
var num = color + '';
while (num.length < 6) {
num += '0';
}
return '#' + num;
};
//todo: think about effectiveness of this method (try another args, new techniques etc)
ColorABC.prototype.createABC = function(str, sym) {
document.getElementById('mainForm').style.display = 'none';
document.getElementById('mainBtn1').style.display = 'none';
document.getElementById('mainBtn2').style.display = 'none';
document.getElementById('mainBtn3').style.display = 'none';
var arrayStr = str.split(sym);
for (var i = 0; i < arrayStr.length; i++) {
var child = document.createElement('div');
var backgroundColor = this.getColor();
child.style.background = backgroundColor;
child.style.display = 'inline';
child.innerHTML = arrayStr[i];
child.style.padding = '0 8px';
document.body.appendChild(child);
}
document.getElementById('secondBtn').style.visibility = 'visible';
};
document.getElementById('mainBtn1').onclick = function () {
(function() {
var str = document.getElementById('textarea').value;
var cABC = new ColorABC();
cABC.createABC(str, '');
}());
};
document.getElementById('mainBtn2').onclick = function() {
(function() {
var str = document.getElementById('textarea').value;
var cABC = new ColorABC(str);
cABC.createABC(str, ' ');
}());
};
document.getElementById('mainBtn3').onclick = function() {
(function() {
var str = document.getElementById('textarea').value;
var cABC = new ColorABC(str);
cABC.createABC(str, '.');
}());
};