-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
357 lines (312 loc) · 13.1 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JS Workbench</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Styles -->
<link href="include/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="include/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<link rel="stylesheet" href="include/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="include/codemirror/theme/eclipse.css">
<link href="jsworkbench.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="include/modernizr-custom.js"></script>
<script type="text/javascript">
window.MISSING = 0;
window.EMULATED = 1;
window.SUPPORTED = 2;
window.features = [
{
name: "File reader",
url: "http://caniuse.com/filereader",
status: Modernizr.filereader ? SUPPORTED : MISSING
},
{
name: "JSON",
url: "http://caniuse.com/json",
status: Modernizr.json ? SUPPORTED : EMULATED
}
];
Modernizr.load([
{
test : Modernizr.json,
nope : ['include/polyfills/json2.js']
}
]);
</script>
</head>
<body>
<!-- Navbar -->
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#">JS Workbench</a>
<ul class="nav pull-right">
<li id="browserIssues" class="dropdown">
<a href="#"
class="dropdown-toggle"
data-toggle="dropdown"
onmouseover="$('#browserStatusMsg').show();"
onmouseout="$('#browserStatusMsg').hide();">
<span id="browserStatus" class="badge">
<i id="browserStatusIcon" class="icon-white"></i>
<span id="browserStatusMsg" class="hide"></span>
<b class="caret"></b>
</span>
</a>
<ul class="dropdown-menu"></ul>
</li>
</ul>
</div>
</div>
</div>
<!-- Content -->
<div class="container">
<!-- Header -->
<div class="row">
<div class="span12">
<p>This is work in progress. Enter some JavaScript code below and click the Run button to execute it. Note that you can use <code>print</code> and <code>println</code> to display some information in the console.</p>
</div>
</div>
<!-- Placeholder for errors, warnings, etc -->
<div class="row"><div id="alerts" class="span12"></div></div>
<div class="row btn-row">
<div class="span12">
<div id="main-toolbar" class="btn-toolbar">
<div class="btn-group">
<a class="btn btn-small" href="#" onclick="jswb.loadSession();">Restore session</a>
<a class="btn btn-small" href="#" onclick="jswb.saveSession();">Save session</a>
<a class="btn btn-small" href="#" onclick="jswb.clearSession();">Clear saved session</a>
</div>
<div class="btn-group">
<a class="btn" href="#" onclick="jswb.loadProject();"><img src="icons/icon-project.png"> Open</a>
<a class="btn" href="#" onclick="jswb.saveProject();"><img src="icons/icon-project.png"> Save</a>
</div>
</div>
</div>
</div>
<!-- Main area (editors) -->
<div class="row">
<div id="editorColumn" class="span8">
<!-- Tab bar -->
<ul id="editor-tabs" class="nav nav-tabs"></ul>
<!-- Toolbar -->
<div id="main-editor-area">
<div id="editor-toolbar" class="btn-toolbar">
<div class="btn-group">
<a class="btn" href="#" onclick="jswb.newTab();"><i class="icon-file"></i></a>
<a class="btn" href="#" onclick="doOpen();"><i class="icon-folder-open"></i></a>
<a class="btn" href="#" onclick="doSave();"><i class="icon-download-alt"></i></a>
</div>
<div class="btn-group">
<a class="btn" href="#" onclick="jswb.undo(jswb.getCurrentTab().editor);"><img src="icons/icon-undo.png"/></a>
<a class="btn" href="#" onclick="jswb.redo(jswb.getCurrentTab().editor);"><img src="icons/icon-redo.png"/></a>
</div>
</div>
<!-- Editors -->
<div id="editors" class="tab-content"></div>
</div>
<!-- Modals (hidden) -->
<div class="modal hide" id="fileOpenDialog">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3>Open file...</h3>
</div>
<div class="modal-body">
<p><form id="fileInputForm"><input type="file" id="fileInput" accept="*" onchange="onFileSelected();"></form></p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Cancel</a>
<a href="#" id="btnOpenFile" class="btn btn-primary disabled">Open</a>
</div>
</div>
<div class="btn-toolbar">
<div class="btn-group">
<button id="btn-run" class="btn btn-primary" onclick="doRunAll();">Run all</button>
<button id="btn-run-dropdown" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#" onclick="doRunCurrent();">Run active file</a></li>
<li><a href="#" onclick="doRunSelection();">Run selection</a></li>
</ul>
</div>
<div class="btn-group">
<button class="btn" onclick="doClear();">Clear</button>
</div>
</div>
</div>
<!-- Output -->
<div id="outputColumn" class="span4">
<div id="outputBoxHeader">Output: <a href="#" onclick="jswb.detachOutput();"><i class="icon-share" style="float:right"></i></a></div>
<div id="mainOutputArea">
<div id="outputBox" class="well outputBox"></div>
<div class="btn-toolbar">
<div class="btn-group">
<a id="btnOutputKind" class="btn dropdown-toggle" data-toggle="dropdown" href="#">
<span class="btnLabel" data-jswb-role="outputKindLabel">No output</span>
<span class="caret"></span>
</a>
<ul id="dropdownOutputKind" class="dropdown-menu" data-jswb-role="outputKindDropdown">
<li><a href="#">No output</a></li>
</ul>
</div>
<div class="btn-group">
<button class="btn" onclick="jswb.clearOutput();">Clear</button>
</div>
</div>
</div>
</div>
</div>
<hr/>
<!-- Console -->
<div class="row">
<div class="span12">Console:
<pre id="repl"><div id="console"></div></pre>
</div>
</div>
</div>
<!-- Imports (importing at the end makes the page load faster) -->
<script src="include/jquery.js"></script>
<script src="include/bootstrap/js/bootstrap.js"></script>
<script src="include/codemirror/lib/codemirror.js"></script>
<script src="include/codemirror/mode/javascript/javascript.js"></script>
<script src="include/cm-autoclose.js"></script>
<script src="include/polyfills/BlobBuilder.js"></script>
<script src="include/polyfills/FileSaver.js"></script>
<script type="text/javascript">
window.jswb = {
builtins: {},
// state
tabs: [],
currentTab: undefined,
currentConsoleLine: undefined,
currentOutput: undefined,
outputPlugins: [],
// Elements
alerts: undefined,
repl: undefined,
console: undefined,
output: undefined,
};
function disableHashLinks() {
$("a").each(function () {
if (this.onclick && (this.href === '#' || this.href === document.baseURI + "#")) {
var oldHandler = this.onclick;
this.onclick = (function (h) {
return function (event) {
event.preventDefault();
h(event);
};
})(oldHandler);
}
});
}
$(document).ready(function() {
checkBrowserFeatures();
jswb.alerts = document.getElementById("alerts");
jswb.repl = createREPL(document.getElementById("repl"));
jswb.console = document.getElementById("console");
jswb.output = document.getElementById("outputBox");
jswb.newTab();
$("#repl").click(focusREPL);
$("#fileOpenDialog").on('show', function () {
// Reset file open model before displaying
document.getElementById('fileInputForm').innerHTML = document.getElementById('fileInputForm').innerHTML;
$("#btnOpenFile").addClass("disabled");
});
// disableHashLinks();
});
function checkBrowserFeatures() {
var MISSING = 0, EMULATED = 1, SUPPORTED = 2;
var status = SUPPORTED;
for (var i = 0; i < window.features.length; i++) {
var feature = window.features[i];
var status_label;
switch (feature.status) {
case MISSING:
status_label = "missing";
break;
case EMULATED:
status_label = "emulated";
break;
default:
status_label = "supported";
break;
}
$("#browserIssues ul").append($("<li/>").append($('<a/>').attr('href', feature.url).attr("target", "new").text(feature.name + " " + status_label)));
status = Math.min(status, feature.status);
}
if (status === SUPPORTED) {
$("#browserStatus").addClass("badge-success");
$("#browserStatusMsg").text("All features supported");
$("#browserStatusIcon").addClass("icon-ok");
} else if (status === EMULATED) {
$("#browserStatus").addClass("badge-warning");
$("#browserStatusMsg").text("Some features are emulated");
$("#browserStatusIcon").addClass("icon-warning-sign");
} else {
$("#browserStatus").addClass("badge-important");
$("#browserStatusMsg").text("Some features are missing");
$("#browserStatusIcon").addClass("icon-exclamation-sign");
}
}
function doOpen() {
var tab = jswb.getCurrentTab();
jswb.load(tab.editor);
}
function onFileSelected() {
$('#btnOpenFile').removeClass('disabled');
}
function doSave() {
var tab = jswb.getCurrentTab();
if (tab) jswb.save(tab.editor);
}
function jswb_internal_run(tabs, mode) {
$("#btn-run").removeClass("btn-primary").addClass("btn-danger").text("Stop");
$("#btn-run-dropdown").removeClass("btn-primary").addClass("btn-danger");
for (var i = 0; i < tabs.length; i++) {
var tab = tabs[i];
if (tab) {
var ed = tab.editor;
var script = mode === "selection" ? ed.getSelection() : ed.getValue();
try {
jswb.runScript(script);
} catch (e) {
jswb.reportError(tab.title + " - " + e);
break;
}
}
}
$("#btn-run").removeClass("btn-danger").addClass("btn-primary").text("Run all");
$("#btn-run-dropdown").removeClass("btn-danger").addClass("btn-primary");
}
function doRunAll() {
jswb_internal_run(jswb.tabs);
}
function doRunCurrent() {
jswb_internal_run([jswb.getCurrentTab()]);
}
function doRunSelection() {
jswb_internal_run([jswb.getCurrentTab()], "selection");
}
function doClear() {
jswb.clearConsole();
}
function focusREPL() {
jswb.repl.focus();
}
</script>
<script src="include/actions.js"></script>
<script src="include/editors.js"></script>
<script src="include/builtins.js"></script>
<script src="include/storage.js"></script>
<script src="include/output.js"></script>
</body>
</html>