forked from processing/processing-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.js
More file actions
99 lines (81 loc) · 2.25 KB
/
generate.js
File metadata and controls
99 lines (81 loc) · 2.25 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
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
var queue = [];
var isCommandRunning = false;
// show the debug window by pressing the "d" key
window.addEventListener("keyup", function(evt) {
if(evt.keyCode == 68) {
document.documentElement.classList.toggle("is-debug-mode");
}
}, false);
// preset buttons
var presets = document.querySelectorAll(".preset-btn");
for(var i=0;i<presets.length;i++) {
var preset = presets[i];
preset.addEventListener("click", function(evt) {
evt.preventDefault();
// clear all checkboxes
var checkboxes = document.querySelectorAll("input[type=checkbox]");
for(var i=0;i<checkboxes.length;i++) {
var checkbox = checkboxes[i];
checkbox.checked = false;
}
// now toggle the ones we need.
var options = JSON.parse(this.getAttribute("data-presets"));
for(var i=0;i<options.length;i++) {
var option = options[i];
var checkbox = document.getElementById(option)
checkbox.checked = true;
}
}, false);
}
// submit button
var submit = document.querySelector(".submit-btn");
submit.addEventListener("click", function(evt) {
evt.preventDefault();
var checkboxes = document.querySelectorAll("input[type=checkbox]:checked");
for(var i=0;i<checkboxes.length;i++) {
var checkbox = checkboxes[i];
var command = {};
command.instruction = checkbox.getAttribute("data-command");
if(checkbox.hasAttribute("data-command-args")) {
command.args = JSON.parse(checkbox.getAttribute("data-command-args"));
}
else {
command.args = {};
}
queue.push(command);
}
if(!isCommandRunning) {
runNextCommand();
}
}, false);
function debug(str) {
console.log(str)
document.querySelector(".debug").innerHTML += "<p>" + str + "</p>";
}
function debugHR() {
console.log("------------------------------------------");
document.querySelector(".debug").innerHTML += "<hr />";
}
// commands
function runNextCommand() {
isCommandRunning = true;
if(queue.length == 0) {
isCommandRunning = false;
debug("All commands are complete.");
return;
}
var command = queue.shift();
debug("Running command :: " + command.instruction);
reqwest({
url: "./" + command.instruction + ".php",
method: "get",
data: command.args,
success: function(data) {
debugHR();
debug(data);
debugHR();
debug("Finished!");
runNextCommand();
}
});
}