-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathEditor.js
55 lines (51 loc) · 1.68 KB
/
Editor.js
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
var Editor = function(ide) {
var container = new UI.Panel();
container.setId('definitions');
var config = new Config('editor');
container.config = config;
var codemirror = CodeMirror(container.dom, {
value: '',
lineNumbers: config.get('lineNumbersShow'),
matchBrackets: true,
lineWrapping: true,
matchBrackets: true,
indentWithTabs: true,
tabSize: 4,
indentUnit: 4,
});
codemirror.setSize('height', "100%");
codemirror.setOption('theme', "scheme-classic-color");
$.extend(container, {
setValue: function(content) {
return codemirror.setValue(content);
},
getValue: function() {
return codemirror.getValue();
},
loadFile: function(files) {
if(!files.length)
return;
var file = files[0];
var reader = new FileReader();
reader.onload = function() {
codemirror.setValue(this.result);
};
reader.onprogress = function ( event ) {
var size = '(' + Math.floor(event.total / 1000).format() + ' KB)';
var progress = Math.floor((event.loaded / event.total) * 100) + '%';
console.log('Loading', filename, size, progress);
};
reader.readAsText(file);
},
command: function(name) {
return codemirror.execCommand(name);
},
setOption: function(key, value) {
return codemirror.setOption(key, value);
},
getOption: function(key) {
return codemirror.getOption(key);
}
});
return container;
}