still tweaking linting
This commit is contained in:
4
app.js
4
app.js
@ -129,13 +129,13 @@ var trusted = [
|
||||
'ws://localhost:3000/',
|
||||
'http://localhost:3000',
|
||||
'*.ionicframework.com',
|
||||
'https://syndication.twitter.com'
|
||||
'https://syndication.twitter.com',
|
||||
];
|
||||
|
||||
debug(trusted);
|
||||
app.use(helmet.contentSecurityPolicy({
|
||||
defaultSrc: trusted,
|
||||
scriptSrc: ['*.optimizely.com'].concat(trusted),
|
||||
scriptSrc: ['*.optimizely.com', '*.aspnetcdn.com'].concat(trusted),
|
||||
'connect-src': [
|
||||
'ws://*.rafflecopter.com',
|
||||
'wss://*.rafflecopter.com',
|
||||
|
@ -1,7 +1,13 @@
|
||||
extends ../layout
|
||||
block content
|
||||
script(src='/js/lib/codemirror/lib/codemirror.js')
|
||||
script(src='/js/lib/codemirror/addon/edit/closebrackets.js')
|
||||
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')
|
||||
|
||||
link(rel='stylesheet', href='/js/lib/codemirror/lib/codemirror.css')
|
||||
link(rel='stylesheet', href='/js/lib/codemirror/addon/lint/lint.css')
|
||||
link(rel='stylesheet', href='/js/lib/codemirror/theme/monokai.css')
|
||||
script(src='/js/lib/codemirror/mode/javascript/javascript.js')
|
||||
|
||||
@ -12,19 +18,24 @@ block content
|
||||
.panel.panel-body
|
||||
form.code
|
||||
.form-group.codeMirrorView
|
||||
textarea#codeEditor
|
||||
textarea#codeEditor(autofocus=true)
|
||||
form.code
|
||||
.form-group.codeMirrorView
|
||||
textarea#codeOutput(enabled=false)
|
||||
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.
|
||||
var widgets = [];
|
||||
var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("codeEditor"), {
|
||||
lineNumbers: true,
|
||||
mode: "javascript",
|
||||
theme: 'monokai',
|
||||
runnable: true
|
||||
runnable: true,
|
||||
autoCloseBrackets: true,
|
||||
gutters: ["CodeMirror-lint-markers"],
|
||||
onKeyEvent : doLinting()
|
||||
});
|
||||
var editor = myCodeMirror;
|
||||
myCodeMirror.setValue('2*2');
|
||||
myCodeMirror.setSize("100%", 500);
|
||||
$('#submitButton').on('click', function () {
|
||||
@ -46,5 +57,33 @@ block content
|
||||
readOnly: 'nocursor'
|
||||
});
|
||||
codeOutput.setSize("100%", 30);
|
||||
|
||||
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());
|
||||
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
|
||||
}));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
.col-sm-12.col-md-4.col-xs-12
|
||||
include ../partials/challenges
|
||||
include ../partials/challenges
|
||||
|
Reference in New Issue
Block a user