Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
.idea
*.iml
*.diff
*.DS_Store
40 changes: 32 additions & 8 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
var App = (function() {

var App = function() {
this.isLightTheme = true;
this.fontSizeSelector = document.getElementById('fontSize');
this.themeSelector = document.getElementById('ideTheme');
this.runButton = document.getElementById('runCode');
this.codeMirror = CodeMirror(document.getElementById('cmContainer'), {
value: 'console.log(\'potato\')\;\n',
mode: 'javascript',
lineNumbers: true,
gutters: ['CodeMirror-lint-markers'],
theme: 'cobalt',
autoCloseBrackets: true,
inputStyle: 'contenteditable'
inputStyle: 'contenteditable',
lint: true
});

// these will be set in the init() function
Expand Down Expand Up @@ -47,11 +49,6 @@ var App = (function() {
// global 'app' variable. A little weird
// but it works ¯\_(ツ)_/¯

var keyup = function() {
var value = app.codeMirror.doc.getValue();
eval(value);
};

var setFontSize = function() {
var fontSize = this.value;
app.cmWrapperElement.style['font-size'] = fontSize;
Expand All @@ -62,9 +59,36 @@ var App = (function() {
app.codeMirror.setOption('theme', theme);
};

self.codeArea.addEventListener('keyup', keyup);
var checkAndRun = function() {
var _value = app.codeMirror.doc.getValue(),
success = JSHINT(_value),
output = '';

if (!success) {
output = 'Check format error:\n\n';

var errors = JSHINT.errors;
for (var i in errors) {
var err = errors[i];

if (err != null) {
output += err.line + '[' + err.character + ']: ' + err.reason + '\n';
} else {
output += 'Check format unknown error:\n';
}
}

alert(output);
} else {
eval(_value);
}

return success;
};

self.fontSizeSelector.addEventListener('change', setFontSize);
self.themeSelector.addEventListener('change', setTheme);
self.runButton.addEventListener('click', checkAndRun);
};

return App;
Expand Down
11 changes: 10 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
<head>
<meta charset="utf-8">
<title>CodeMirror</title>
<script src="lib/codemirror.js"></script>
<link rel="stylesheet" href="lib/codemirror.css">
<link rel="stylesheet" href="theme/3024-day.css">
<link rel="stylesheet" href="theme/3024-night.css">
<link rel="stylesheet" href="theme/midnight.css">
<link rel="stylesheet" href="theme/eclipse.css">
<link rel="stylesheet" href="theme/cobalt.css">
<link rel="stylesheet" href="theme/monokai.css">
<link rel="stylesheet" href="addon/lint/lint.css">
<link rel="stylesheet" href="style.css">

<script src="lib/codemirror.js"></script>
<script src="mode/javascript/javascript.js"></script>
<script type="text/javascript" src="vendor/jshint.js"></script>
<script src="keymap/vim.js"></script>
<script src="addon/edit/closebrackets.js"></script>
<script src-"addon/lint/lint.js"></script>
<script src="addon/lint/javascript-lint.js"></script>
</head>

<body style='font-size: 14px;'>
Expand Down Expand Up @@ -61,6 +66,10 @@ <h1>
<option value="72px">72px</option>
</select>
</div>

<div>
<button id="runCode">Run Code</button>
</div>

<!-- <div id="noOfLines" aria-live="assertive" > no Of lines - 10 </div> -->
<script src="app.js"></script>
Expand Down
24,203 changes: 24,203 additions & 0 deletions vendor/jshint.js

Large diffs are not rendered by default.