-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocks.js
70 lines (63 loc) · 1.64 KB
/
blocks.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
const SELECT = function(){
let temp = document.createElement('select');
let arr = ['none', 'move', 'loop', 'if', 'while'];
add_options(arr, temp);
temp.setAttribute("onchange", 'on_change.add(this)');
temp.classList.add('branch');
return temp;
}
const DIRECTION = function(attribute){
let temp = document.createElement('select');
let arr = ['none', 'up', 'down', 'left', 'right'];
add_options(arr, temp);
temp.classList.add(attribute);
temp.classList.add('leaf');
return temp;
}
const LOOPS = function(attribute){
let temp = document.createElement('input');
temp.setAttribute("type", 'text');
temp.value = 0;
temp.classList.add(attribute);
temp.classList.add('leaf');
return temp;
}
const STATEMENT = function(attribute){
let temp = document.createElement('select');
let arr = ['none','re','gr','bu','ye','or','pu','bl','wh'];
add_options(arr, temp);
temp.classList.add(attribute);
temp.classList.add('leaf');
return temp;
}
const HOLDER = function(attribute){
let temp = document.createElement('section');
temp.setAttribute("class", attribute);
return temp;
}
const ENDLINE = function(attribute){
let temp = document.createElement('br');
temp.setAttribute("class", attribute);
return temp;
}
function add_options(arr, opt){
for(let i = 0; arr[i]||opt.options[i]; ){
if (arr[i]) {
if (!opt.options[i]) {
let temp = document.createElement("option");
temp.text = arr[i];
//temp.setAttribute("class", arr[i]);
opt.add(temp);
}else{
opt.options[i].text = arr[i];
}
i++
}else{
opt.options[i] = null;
}
}
opt.value = arr[0];
}
function random(){
return Math.floor((Math.random() * 100000) + 1);
}