-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
42 lines (35 loc) · 923 Bytes
/
code.js
File metadata and controls
42 lines (35 loc) · 923 Bytes
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
// Setup ACE
let codeEditor=ace.edit("editorCode");;
// Retrive Elements
const exeCode=document.getElementById('run');
const resetCode=document.getElementById('reset');
let editorLib={
init(){
//Configure ACE
//Theme
codeEditor.setTheme("ace/theme/github");
//Set Language
codeEditor.session.setMode("ace/mode/javascript");
//Set Options
codeEditor.setOptions({
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
});
}
}
//Events
exeCode.addEventListener('click',()=>{
//Get input from code editor
const userCode=codeEditor.getValue();
//Run the user codeEditor
try{
new Function(userCode)();
}
catch(err){
console.log(err);
}
});
resetCode.addEventListener('click',()=>{
codeEditor.setValue('');
})
editorLib.init();