index.html 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  5. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
  6. </head>
  7. <body>
  8. <h2>Monaco Diff Editor Sample</h2>
  9. <div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
  10. <script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
  11. <script>
  12. require.config({ paths: { 'vs': '../node_modules/monaco-editor/min/vs' }});
  13. require(['vs/editor/editor.main'], function() {
  14. var diffEditor = monaco.editor.createDiffEditor(document.getElementById('container'));
  15. monaco.Promise.join([xhr('original.txt'), xhr('modified.txt')]).then(function(r) {
  16. var originalTxt = r[0].responseText;
  17. var modifiedTxt = r[1].responseText;
  18. diffEditor.setModel({
  19. original: monaco.editor.createModel(originalTxt, 'javascript'),
  20. modified: monaco.editor.createModel(modifiedTxt, 'javascript'),
  21. })
  22. });
  23. });
  24. </script>
  25. <script>
  26. function xhr(url) {
  27. var req = null;
  28. return new monaco.Promise(function(c,e,p) {
  29. req = new XMLHttpRequest();
  30. req.onreadystatechange = function () {
  31. if (req._canceled) { return; }
  32. if (req.readyState === 4) {
  33. if ((req.status >= 200 && req.status < 300) || req.status === 1223) {
  34. c(req);
  35. } else {
  36. e(req);
  37. }
  38. req.onreadystatechange = function () { };
  39. } else {
  40. p(req);
  41. }
  42. };
  43. req.open("GET", url, true );
  44. req.responseType = "";
  45. req.send(null);
  46. }, function () {
  47. req._canceled = true;
  48. req.abort();
  49. });
  50. }
  51. </script>
  52. </body>
  53. </html>