modelist.html 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <title>ACE Editor Modelist Demo</title>
  7. <style type="text/css" media="screen">
  8. body {
  9. overflow: hidden;
  10. }
  11. #editor {
  12. margin: 0;
  13. position: absolute;
  14. top: 0;
  15. bottom: 0;
  16. left: 0;
  17. right: 0;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <pre id="editor"></pre>
  23. <script src="kitchen-sink/require.js"></script>
  24. <script>
  25. // setup paths
  26. require.config({paths: { "ace" : "../lib/ace"}});
  27. // load ace and extensions
  28. require(["ace/ace", "ace/ext/modelist"], function(ace) {
  29. var editor = ace.edit("editor");
  30. editor.setTheme("ace/theme/twilight");
  31. (function () {
  32. var modelist = ace.require("ace/ext/modelist");
  33. // the file path could come from an xmlhttp request, a drop event,
  34. // or any other scriptable file loading process.
  35. // Extensions could consume the modelist and use it to dynamically
  36. // set the editor mode. Webmasters could use it in their scripts
  37. // for site specific purposes as well.
  38. var filePath = "blahblah/weee/some.js";
  39. var mode = modelist.getModeForPath(filePath).mode;
  40. console.log(mode);
  41. editor.session.setMode(mode);
  42. }());
  43. })
  44. </script>
  45. <script src="./show_own_source.js"></script>
  46. </body>
  47. </html>