ace.js 838 B

1234567891011121314151617181920212223242526272829303132333435
  1. var editor;
  2. onload=function(){
  3. var d=document;
  4. var ext = location.href.split('.').pop();
  5. {
  6. var ta=d.getElementById("textarea");
  7. var text=ta.value;
  8. var e = d.getElementById("editor");
  9. switch(ext){
  10. case "js":
  11. ext = "javascript";
  12. break;
  13. case "py":
  14. ext = "python";
  15. break;
  16. }
  17. editor = ace.edit(e);
  18. editor.session.setValue(text);
  19. }
  20. editor.session.setMode("ace/mode/"+ext);
  21. editor.setTheme("ace/theme/clouds");
  22. editor.setShowPrintMargin(false);
  23. editor.setOptions({
  24. enableBasicAutocompletion: true,
  25. enableSnippets: true,
  26. enableLiveAutocompletion: true
  27. });
  28. }
  29. function onSave(fn){
  30. let u8=new TextEncoder().encode(editor.session.getValue());let r='';for(let i=0;i<u8.byteLength;i++)r+=String.fromCharCode(u8[i]);location.href='i:0l'+fn+':'+btoa(r);
  31. }