-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodemirror.html
More file actions
239 lines (236 loc) · 7.53 KB
/
Copy pathcodemirror.html
File metadata and controls
239 lines (236 loc) · 7.53 KB
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
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="js/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="js/codemirror/addon/hint/show-hint.css">
<style type="text/css">
.CodeMirror {
border-width:1px;
border-style: solid;
border-color:#DBDFE6;
}
.fixed-top .CodeMirror {
height: 500px;
}
.CodeMirror-foldmarker {
color: blue;
text-shadow: #b9f 1px 1px 2px, #b9f -1px -1px 2px, #b9f 1px -1px 2px, #b9f -1px 1px 2px;
line-height: .3;
cursor: pointer;
}
.tabs input[type=radio] {
position: absolute;
top: -9999px;
left: -9999px;
}
.tabs {
float: none;
list-style: none;
position: relative;
padding: 0;
}
.tabs li {
float: left;
}
.tabs label {
display: block;
padding: 10px 20px;
border-radius: 2px 2px 0 0;
color: #EEE8D5;
font-size: 24px;
font-weight: normal;
background: rgba(255, 255, 255, 0.2);
cursor: pointer;
position: relative;
top: 3px;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
.tabs label:hover {
background: rgba(255, 255, 255, 0.5);
top: 0;
}
[id^=tab]:checked + label {
background: #1B6CA5;
color: #EEE8D5;
top: 0;
}
[id^=tab]:checked ~[id^=tab-content] {
display: block;
}
.tab-content {
z-index: 2;
display: none;
text-align: left;
width: 100%;
font-size: 20px;
line-height: 140%;
padding-top: 10px;
background: #1B6CA5;
padding: 15px;
color: white;
position: absolute;
top: 47px;
left: 0;
box-sizing: border-box;
-webkit-animation-duration: 0.5s;
-o-animation-duration: 0.5s;
-moz-animation-duration: 0.5s;
animation-duration: 0.5s;
}
.tab-content .button {
position: absolute;
top: 20px;
z-index: 10;
right: 20px;
background-color:#44c767;
-moz-border-radius:28px;
-webkit-border-radius:28px;
border-radius:28px;
border:1px solid #18ab29;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-family:Arial;
font-size:17px;
padding:6px 31px;
text-decoration:none;
text-shadow:0px 1px 0px #2f6627;
}
.tab-content .button:hover {
background-color:#5cbf2a;
}
.tab-content .button:active {
top:21px;
}
.select {
float: right !important;
}
.select select {
width: 200px;
height: 30px;
margin-top: 10px;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<ul class="tabs">
<li>
<input type="radio" checked name="tabs" id="tab1">
<label for="tab1">Code</label>
<div id="tab-content1" class="tab-content animated fadeIn">
<textarea id="code">
</textarea>
</div>
</li>
<li>
<input type="radio" name="tabs" id="tab2">
<label for="tab2">Output</label>
<div id="tab-content3" class="tab-content animated fadeIn"> <span class="button" onclick="runCode();"> Run </span>
<textarea id="output" disabled></textarea>
</div>
</li>
<li class="select">
<select id="select-box"></select>
</li>
</ul>
<script src="js/codemirror/lib/codemirror.js"></script>
<script src="js/codemirror/addon/hint/show-hint.js"></script>
<script src="js/codemirror/addon/hint/javascript-hint.js"></script>
<script src="js/codemirror/mode/javascript/javascript.js"></script>
<script>
(function(){
'use strict';
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
matchBrackets: true,
continueComments: "Enter",
mode: {
name: "javascript",
globalVars: true
},
gutters: ["CodeMirror-lint-markers"],
lint: true,
extraKeys: {
"Ctrl-Q": "toggleComment",
"Ctrl-Space": "autocomplete"
}
});
var media = window.frameElement? window.frameElement.getAttribute("data-media"): null;
if(media !== null) {
loadFile("code/" + window.frameElement.getAttribute("data-media") + ".text")
}
var classList = window.frameElement? window.frameElement.classList: null;
if(classList !== null && classList.length !== 0){
document.body.classList.add(classList[0]);
}
function loadFile(filename) {
$.ajax({
url: filename + '?' + (new Date()).getTime(),
dataType: "text",
success: function (data) {
editor.setValue(data)
}
});
}
function takeOverConsole(){
var console = window.console;
if (!console) return;
function intercept(method){
var original = console[method];
console[method] = function(){
// do sneaky stuff
output.setValue(output.getValue() + Array.prototype.slice.apply(arguments).join(' ') + '\n');
if (original.apply){
// Do this for normal browsers
original.apply(console, arguments);
}else{
// Do this for IE
var message = Array.prototype.slice.apply(arguments).join(' ');
original(message);
}
}
}
var methods = ['log', 'warn', 'error', 'info'];
for (var i = 0; i < methods.length; i++)
intercept(methods[i]);
}
takeOverConsole();
window.runCode = function () {
(function () {
output.setValue('');
try {
eval(editor.getValue())
} catch (e) {
if (e) {
output.setValue(e.stack);
}
}
})()
};
window.output = CodeMirror.fromTextArea(document.getElementById("output"), {
readOnly: true
});
var select = $('#select-box');
select.toggle();
function enableSelectBox(){
$.get('codelist.json',function(data){
var list = data;
select[0].add(new Option('Select', ''));
for(var i=0; i < list.length; i++) {
select[0].add(new Option(list[i], list[i]));
}
});
select.toggle();
select.on('change', function() {
loadFile(this.value);
});
}
enableSelectBox();
})( );
</script>
</body>
</html>