compress.html 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <title>CodeMirror: Script Compression</title>
  4. <link rel="stylesheet" type="text/css" href="css/docs.css"/>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6. <style type="text/css">
  7. .field {border: 1px solid black; padding: .4em;}
  8. button {border: 1px solid black; background-color: #eee;}
  9. </style>
  10. </head>
  11. <body>
  12. <div class="top underline" style="text-align: center">
  13. <h1 style="margin-bottom: 0;"><a href="index.html" style="text-decoration: none; color: black;">CodeMirror</a></h1>
  14. <h2 style="margin-top: 0; margin-bottom: .3em;">Script Compression</h2>
  15. </div>
  16. <p>The CodeMirror scripts, as distributed, are many, and full of
  17. comments. To optimize page loading, it is recommended to
  18. concatenate the scripts loaded in the CodeMirror frame, and
  19. compress them. This page may be useful if you intend to do this:
  20. it provides an interface go Google's <a
  21. href="http://closure-compiler.appspot.com/">Closure compiler</a>,
  22. allowing you to easily load in CodeMirror scripts.</p>
  23. <p>You will have to compress <code>codemirror.js</code>
  24. separately, since that will be loaded into the top-level page from
  25. which you use CodeMirror. Inside the frame, the
  26. <code>parserfile</code> and <code>basefiles</code> options control
  27. which files are loaded. If you combine the parser(s) you need with
  28. the basefiles, you can set <code>basefiles</code> to point at your
  29. compressed file, and leave <code>parserfiles</code> at
  30. <code>[]</code>.</p>
  31. <p>For example, you have a page that uses CodeMirror to edit some
  32. JavaScript code. You could save a minimized version of
  33. <code>codemirror.js</code> as <code>codemirror_min.js</code>, and
  34. include that (with a <code>&lt;script></code> tag) in your page.
  35. Next, you compress all the files under "In-frame base code", plus
  36. <code>tokenizejavascript.js</code> and
  37. <code>parsejavascript.js</code> into
  38. <code>codemirror_base.js</code>, and load the editor like
  39. this:</p>
  40. <pre class="code">CodeMirror.fromTextArea("mytextarea", {
  41. basefiles: ["js/codemirror_base.js"],
  42. lineNumbers: true
  43. });</pre>
  44. <p>Clicking the "Compress" buttons below will take you to a file
  45. containing the compressed code. Copy-paste this into your script
  46. file. ("Save as" for that page is broken on some browsers, so be
  47. careful).</p>
  48. <script type="text/javascript">
  49. function setVersion(ver) {
  50. var urlprefix = ver.options[ver.selectedIndex].value;
  51. console.log(urlprefix);
  52. var select = document.getElementById("files"), m;
  53. for (var optgr = select.firstChild; optgr; optgr = optgr.nextSibling)
  54. for (var opt = optgr.firstChild; opt; opt = opt.nextSibling) {
  55. if (opt.nodeName != "OPTION")
  56. continue;
  57. else if (m = opt.value.match(/^http:\/\/marijn.haverbeke.nl\/codemirror\/(.*)$/))
  58. opt.value = urlprefix + m[1];
  59. else if (m = opt.value.match(/http:\/\/marijn.haverbeke.nl\/git\/codemirror\?a=blob_plain;hb=[^;]+;f=(.*)$/))
  60. opt.value = urlprefix + m[1];
  61. }
  62. }
  63. function verify() {
  64. document.getElementById("output").value="warnings";
  65. document.getElementById("form").submit();
  66. document.getElementById("output").value="compiled_code";
  67. }
  68. </script>
  69. <form id="form" action="http://closure-compiler.appspot.com/compile" method="post" id="form">
  70. <p>Version: <select id="version" onchange="setVersion(this);" class="field" style="padding: 1px">
  71. <option value="http://marijn.haverbeke.nl/codemirror/" selected>Development head</option>
  72. <option value="http://marijn.haverbeke.nl/git/codemirror?a=blob_plain;hb=v0.8;f=">v0.8</option>
  73. <option value="http://marijn.haverbeke.nl/git/codemirror?a=blob_plain;hb=v0.7;f=">v0.7</option>
  74. <option value="http://marijn.haverbeke.nl/git/codemirror?a=blob_plain;hb=v0.67;f=">v0.67</option>
  75. <option value="http://marijn.haverbeke.nl/git/codemirror?a=blob_plain;hb=v0.66;f=">v0.66</option>
  76. </select></p>
  77. <p><input type="hidden" value="compiled_code" name="output_info" id="output"/>
  78. <select multiple="multiple" name="code_url" style="width: 40em;" class="field" id="files">
  79. <optgroup label="CodeMirror Library">
  80. <option value="http://marijn.haverbeke.nl/codemirror/js/codemirror.js">codemirror.js</option>
  81. </optgroup>
  82. <optgroup label="In-frame base files">
  83. <option value="http://marijn.haverbeke.nl/codemirror/js/util.js">util.js</option>
  84. <option value="http://marijn.haverbeke.nl/codemirror/js/stringstream.js">stringstream.js</option>
  85. <option value="http://marijn.haverbeke.nl/codemirror/js/select.js">select.js</option>
  86. <option value="http://marijn.haverbeke.nl/codemirror/js/undo.js">undo.js</option>
  87. <option value="http://marijn.haverbeke.nl/codemirror/js/editor.js">editor.js</option>
  88. <option value="http://marijn.haverbeke.nl/codemirror/js/tokenize.js">tokenize.js</option>
  89. </optgroup>
  90. <optgroup label="Parsers">
  91. <option value="http://marijn.haverbeke.nl/codemirror/js/tokenizejavascript.js">tokenizejavascript.js</option>
  92. <option value="http://marijn.haverbeke.nl/codemirror/js/parsejavascript.js">parsejavascript.js</option>
  93. <option value="http://marijn.haverbeke.nl/codemirror/js/parsexml.js">parsexml.js</option>
  94. <option value="http://marijn.haverbeke.nl/codemirror/js/parsecss.js">parsecss.js</option>
  95. <option value="http://marijn.haverbeke.nl/codemirror/js/parsesparql.js">parsesparql.js</option>
  96. <option value="http://marijn.haverbeke.nl/codemirror/js/parsehtmlmixed.js">parsehtmlmixed.js</option>
  97. <option value="http://marijn.haverbeke.nl/codemirror/js/parsedummy.js">parsedummy.js</option>
  98. </optgroup>
  99. <optgroup label="Contributed parsers">
  100. <option value="http://marijn.haverbeke.nl/codemirror/contrib/lua/js/parselua.js">parselua.js</option>
  101. <option value="http://marijn.haverbeke.nl/codemirror/contrib/python/js/parsepython.js">parsepython.js</option>
  102. <option value="http://marijn.haverbeke.nl/codemirror/contrib/php/js/tokenizephp.js">tokenizephp.js</option>
  103. <option value="http://marijn.haverbeke.nl/codemirror/contrib/php/js/parsephp.js">parsephp.js</option>
  104. <option value="http://marijn.haverbeke.nl/codemirror/contrib/php/js/parsephphtmlmixed.js">parsephphtmlmixed.js</option>
  105. <option value="http://marijn.haverbeke.nl/codemirror/contrib/csharp/js/tokenizecsharp.js">tokenizecsharp.js</option>
  106. <option value="http://marijn.haverbeke.nl/codemirror/contrib/csharp/js/parsecsharp.js">parsecsharp.js</option>
  107. <option value="http://marijn.haverbeke.nl/codemirror/contrib/sql/js/parsesql.js">parsesql.js</option>
  108. <option value="http://marijn.haverbeke.nl/codemirror/contrib/plsql/js/parseplsql.js">parseplsql.js</option>
  109. <option value="http://svn.exoplatform.org/projects/gwt/trunk/exo.gwtframework.editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/js/tokenizegroovy.js">tokenizegroovy.js</option>
  110. <option value="http://svn.exoplatform.org/projects/gwt/trunk/exo.gwtframework.editor/src/main/resources/org/exoplatform/gwtframework/editor/public/codemirror/js/parsegroovy.js">parsegroovy.js</option>
  111. </optgroup>
  112. </select></p>
  113. <p><button type="submit">Compress!</button> <button type="button" onclick="verify();">Check for errors</button></p>
  114. <p>Custom code to add to the compressed file:<textarea name="js_code" style="width: 100%; height: 15em;" class="field"></textarea></p>
  115. </form>
  116. </body>
  117. </html>