freeCodeCamp/views/bonfire/bonfire.jade

93 lines
4.5 KiB
Plaintext
Raw Normal View History

2015-01-10 20:21:03 +00:00
extends ../layout
block content
script(src='/js/lib/codemirror/lib/codemirror.js')
2015-01-11 08:07:41 +00:00
script(src='/js/lib/codemirror/addon/edit/closebrackets.js')
2015-01-17 02:55:01 +00:00
script(src='/js/lib/codemirror/addon/edit/matchbrackets.js')
2015-01-11 08:07:41 +00:00
script(src='/js/lib/codemirror/addon/lint/lint.js')
script(src='/js/lib/codemirror/addon/lint/javascript-lint.js')
script(src='//ajax.aspnetcdn.com/ajax/jshint/r07/jshint.js')
2015-01-10 20:21:03 +00:00
link(rel='stylesheet', href='/js/lib/codemirror/lib/codemirror.css')
2015-01-11 08:07:41 +00:00
link(rel='stylesheet', href='/js/lib/codemirror/addon/lint/lint.css')
2015-01-10 20:21:03 +00:00
link(rel='stylesheet', href='/js/lib/codemirror/theme/monokai.css')
script(src='/js/lib/codemirror/mode/javascript/javascript.js')
script(src='js/lib/jailed/jailed.js')
script(src='/js/lib/bonfire/bonfire.js')
2015-01-10 20:21:03 +00:00
.row
.col-sm-12.col-md-8.col-xs-12
.panel.panel-primary
.panel-heading Title
.panel.panel-body
form.code
.form-group.codeMirrorView
2015-01-11 08:07:41 +00:00
textarea#codeEditor(autofocus=true)
form.code
.form-group.codeMirrorView
2015-01-11 08:07:41 +00:00
textarea#codeOutput
#submitButton.btn.btn-primary.btn-big.btn-block Run my code
#hintButton.btn.btn-info.btn-big.btn-block Show me hints
script.
2015-01-11 08:07:41 +00:00
var widgets = [];
var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("codeEditor"), {
lineNumbers: true,
mode: "javascript",
theme: 'monokai',
2015-01-11 08:07:41 +00:00
runnable: true,
2015-01-17 02:55:01 +00:00
lint: true,
matchBrackets: true,
2015-01-11 08:07:41 +00:00
autoCloseBrackets: true,
gutters: ["CodeMirror-lint-markers"],
onKeyEvent : doLinting
});
2015-01-11 08:07:41 +00:00
var editor = myCodeMirror;
myCodeMirror.setValue('2*2');
myCodeMirror.setSize("100%", 500);
2015-01-10 20:21:03 +00:00
var codeOutput = CodeMirror.fromTextArea(document.getElementById("codeOutput"), {
lineNumbers: false,
mode: "javascript",
theme: 'monokai',
readOnly: 'nocursor'
});
codeOutput.setSize("100%", 100);
2015-01-11 08:07:41 +00:00
var info = editor.getScrollInfo();
var after = editor.charCoords({line: editor.getCursor().line + 1, ch: 0}, "local").top;
if (info.top + info.clientHeight < after)
editor.scrollTo(null, after - info.clientHeight + 3);
var doLinting = function() {
editor.operation(function () {
for (var i = 0; i < widgets.length; ++i)
editor.removeLineWidget(widgets[i]);
widgets.length = 0;
JSHINT(editor.getValue());
2015-01-11 08:07:41 +00:00
for (var i = 0; i < JSHINT.errors.length; ++i) {
var err = JSHINT.errors[i];
if (!err) continue;
var msg = document.createElement("div");
var icon = msg.appendChild(document.createElement("span"));
icon.innerHTML = "!!";
icon.className = "lint-error-icon";
msg.appendChild(document.createTextNode(err.reason));
msg.className = "lint-error";
widgets.push(editor.addLineWidget(err.line - 1, msg, {
coverGutter: false,
noHScroll: true
2015-01-11 08:07:41 +00:00
}));
}
});
};
$('#submitButton').on('click', function () {
$('#codeOutput').empty();
var js = myCodeMirror.getValue();
submit(js);
});
2015-01-11 08:07:41 +00:00
.col-sm-12.col-md-4.col-xs-12
2015-01-11 08:07:41 +00:00
include ../partials/challenges