forked from isaacg1/pyth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·199 lines (171 loc) · 5.03 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!doctype html>
<html>
<head>
<title>Pyth Compiler/Executor</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<link rel="shortcut icon" href="/favicon2.ico">
<style type="text/css">
.bottom-row {
float: right;
}
#code {
margin-bottom: 25px;
margin-top: 15px;
}
#input {
margin-bottom: 5px;
}
pre.scroll {
max-height: 20%;
overflow: auto;
}
#table-container {
overflow: auto;
}
.full {
width: 100%;
}
.Char {
width: 15%;
}
.Arity {
width: 10%;
}
.Starts {
width: 10%;
}
.Mnemonic {
width: 25%;
}
.Details {
width: 40%;
overflow: auto;
}
.search-bar {
margin-top: 25px;
margin-bottom: 15px;
padding-left: 0px;
margin-left: 0px;
}
#search-type-menu a {
cursor: pointer;
}
#output-container {
display: none;
}
</style>
</head>
<body>
<div class="container">
<h3><a href="https://github.com/isaacg1/pyth">Pyth</a> Compiler/Executor</h3>
<br>
<div class="row">
<div class="col-md-5">
<div id="output-container">
Output:
<pre class="scroll" id="output"></pre>
</div>
<button id="run-button" class="btn btn-primary">Run Program!</button>
<textarea id="code" placeholder="Code" class="form-control" rows="7"></textarea>
<textarea id="input" placeholder="Input" class="form-control" rows="7"></textarea>
<div class='bottom-row'>
Debug on?: <input id="debug" type="checkbox" checked>
</div>
<br>
<br>
<p>Code length: <span id="length">0</span></p>
<p>Compiler last updated: {{formatted_time}} UTC</p>
</div>
<div class="col-md-1"></div>
<div class="col-md-6 docs">
<h4>Pyth Character Reference</h4>
<div class="search-bar input-group">
<input id="query" class="form-control" placeholder="Search">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropwdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span id="search-type-name"></span> <span class="caret"></span>
</button>
<ul id="search-type-menu" class="dropdown-menu dropdown-menu-right" role="menu"></ul>
</div>
</div>
<div id="table-container">
<table id="docs-table" class="scroll full table table-hover table-condensed"></table>
</div>
</div>
</div>
</div>
<script>
$(function() {
$('#run-button').click(function() {
$.post('/submit', {
code: $('#code').val(),
input: $('#input').val(),
debug: $('#debug').is(':checked')? 1: 0
}, function(data) {
$('#output').text(data);
$('#output-container').show();
});
});
$('#code').keyup(function(e) {
$('#length').text(e.target.value.length);
});
var docs_cols = ['Char', 'Arity', 'Starts', 'Mnemonic', 'Details'];
var search_type;
function search() {
var query = $('#query').val().toLowerCase();
$('#docs-table tbody tr').each(function() {
var $this = $(this);
var matches = $this.find('td').map(function(i) {
return (search_type === -1 || i === search_type) && this.textContent.toLowerCase().indexOf(query) !== -1;
}).index(true) !== -1;
$this.css('display', matches? '': 'none');
});
}
$('#query').keyup(search);
function change_search_type(e) {
var name = e.target.textContent;
$('#search-type-name').text(name);
search_type = docs_cols.indexOf(name);
search();
}
for(var i = -1; i < docs_cols.length; i++) {
$('#search-type-menu').append(
$('<li>').append(
$('<a>').text(i === -1? 'Any': docs_cols[i]).click(change_search_type)
)
);
}
$('#search-type-menu > li > a').eq(0).click();
$.get('/web-docs.txt', function(data) {
var lines = data.split('\n');
var table = $('#docs-table');
var header = $('<thead>').append(
$('<tr>').append(docs_cols.map(function(col_name) {
return $('<th>').attr('class', col_name).text(col_name);
}))
);
var rows = lines.map(function(line) {
var words = line.split(' ');
var details_offset = docs_cols.length - 1;
var tokens = words.slice(0, details_offset);
var details = words.slice(details_offset).join(' ');
tokens.push(details);
var cells = tokens.map(function(token, i) {
return $('<td>').attr('class', docs_cols[i]).text(token);
});
return $('<tr>').attr('class', 'full').append(cells);
});
table.append(header).append($('<tbody>').append(rows));
});
// XXX: This is a hack, I couldn't figure out how to do it with plain css
function onresize() {
$('#table-container').css('height', window.innerHeight - 250);
}
window.addEventListener('resize', onresize);
onresize();
});
</script>
</body>
</html>