forked from RebelOfDeath/reject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
158 lines (127 loc) · 4.42 KB
/
index.html
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Reject Editor</title>
<link rel="icon" type="image/x-icon" href="/img/shark.svg">
<!-- CSS -->
<link rel="stylesheet" href="editor.css">
<!-- External libraries -->
<script src="https://kit.fontawesome.com/c4273b1dc8.js" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- Language files -->
<script src="./bundle.js"></script>
</head>
<body>
<nav>
<div id="run" title="Run your code">
<i class="fa-solid fa-play"></i>
</div>
<div id="reset" title="Clear your code">
<i class="fa-solid fa-trash"></i>
</div>
<div id="download" title="Download your current text">
<i class="fa-solid fa-download"></i>
</div>
<div id="charts" title="View generated graphs">
<i class="fa-solid fa-chart-line"></i>
</div>
<div id="docs" title="View documentation">
<a href="https://github.com/RebelOfDeath/reject/wiki" target="_blank">
<i class="fa-solid fa-book"></i>
</a>
</div>
<div id="src" title="View GitHub">
<a href="https://github.com/RebelOfDeath/reject" target="_blank">
<i class="fa-brands fa-github"></i>
</a>
</div>
<div id="credits">
Reject Editor 1.3.0 / by Efnilite
</div>
</nav>
<main>
<textarea autofocus placeholder="" title="Your code" id="code">
</textarea>
<textarea readonly placeholder="" title="The console" id="console">
</textarea>
<div id="graphs">
<div id="graphs-title">
<span id="graphs-close">[x]</span>
<span>Your Generated Graphs</span>
</div>
<div id="graphs-content">
</div>
</div>
</main>
<script>
// avoid jQuery loading errors by waiting until page has loaded
$(document).ready(function() {
// for some reason the text areas aren't clear by default???
clearConsole();
clearCode();
$("#code").val("# Example graph\nf_top = :(x): sqrt(1 - (|x| - 1)^2)\nf_bot = :(x): arccos(1 - |x|) - pi\n\nplot_functions(-2, 2, 0.01, f_top, f_bot)");
log("Welcome to the Reject IDE!");
log("This area is your console.");
log("Use the 'print' function to log stuff here.");
log("You can start writing your code in the left text area.");
log("Click on the green 'Run' button to run your code!");
$("#run").click(() => {
clearConsole();
clearGraphs();
try {
rejectBundle($("#code").val());
} catch (error) {
log(error.message);
console.log(error);
}
});
$("#reset").click(() => {
clearCode();
clearConsole();
});
$("#download").click(() => {
// transform all text in code area to a blob (stores data)
const blob = new Blob([$("#code").val()], { type: "text/plain" });
const download = document.createElement("a");
download.download = "reject-" + new Date().toLocaleString().replaceAll(/\D/, "") + ".txt";
download.href = window.URL.createObjectURL(blob);
download.click()
});
$("#charts").click(() => {
showGraphs();
});
$("#graphs-close").click(() => {
$("#graphs").css("visibility", "hidden");
});
});
function clearCode() {
$("#code").val("");
}
function clearConsole() {
$("#console").val("");
}
function clearGraphs() {
$("#graphs-content").empty();
}
function log(x) {
let console = $("#console");
console.val((i, txt) => {
return txt + (txt === "" ? x.toString() : ("\n" + x.toString()));
});
console.scrollTop(console[0].scrollHeight);
}
function showGraphs() {
$("#graphs").css("visibility", "visible");
}
function createCanvas() {
const id = Math.floor(Math.random() * 1_000_000);
$("#graphs-content").append($(`<canvas id="${id}" title="" width="16" height="9" role="img"></canvas>`));
return id;
}
</script>
</body>
</html>