index.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. <link href="style.css" rel="stylesheet" type="text/css">
  7. <title>Ace Bookmarklet Builder</title>
  8. </head>
  9. <body>
  10. <div id="wrapper">
  11. <div class="content" style="width: 950px">
  12. <div class="column1" style="margin-top: 47px">
  13. <textarea id="textarea" style="width:300px; height:300px">
  14. /**
  15. * This is Ace injected using a bookmarklet.
  16. */
  17. function foo() {
  18. var bar = true;
  19. }</textarea><br>
  20. SourceUrl: <br>
  21. <input id="srcURL" style="width:300px" value="https://ajaxorg.github.io/ace-builds/src-noconflict"></input><br>
  22. <br>
  23. <a href="#" onmouseover="buildBookmarklet()" onmousedown="buildBookmarklet()" class="bookmarkletLink">Ace Bookmarklet Link</a>
  24. <br>
  25. <br>
  26. <a href="https://github.com/ajaxorg/ace/">
  27. <div class="fork_on_github"></div>
  28. </a>
  29. </div>
  30. <div class="column2">
  31. <h1>Ace Bookmarklet Builder</h1>
  32. <p id="first">
  33. </p>
  34. <h2>How to use it:</h2>
  35. <ul>
  36. <li>Select the options as you want them to be by default.</li>
  37. <li>Enter the "SourceUrl". This has to be the URL pointing to a folder containing ace.js (you can leave the default to load the scripts from GitHub).</li>
  38. <li>Drag the <a href="#" onmouseover="buildBookmarklet()" onmousedown="buildBookmarklet()" class="bookmarkletLink">"Ace Bookmarklet Link"</a> link to your toolbar or store it somewhere else.</li>
  39. <li>Click the bookmarklet.</li>
  40. <li>Click three times on a textarea you want to replace - Ace will replace it.</li>
  41. <li>To change settings, use <strong>Ctrl-,</strong> shortcut. (<strong>Cmd-,</strong> on mac).</li>
  42. </ul>
  43. <textarea cols="80">Test bookmarklet here!</textarea>
  44. </div>
  45. </div>
  46. </div>
  47. <script>
  48. function inject(options, callback) {
  49. var load = function(path, callback) {
  50. var head = document.getElementsByTagName('head')[0];
  51. var s = document.createElement('script');
  52. s.src = options.baseUrl + "/" + path;
  53. head.appendChild(s);
  54. s.onload = s.onreadystatechange = function(_, isAbort) {
  55. if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
  56. s = s.onload = s.onreadystatechange = null;
  57. if (!isAbort)
  58. callback();
  59. }
  60. };
  61. };
  62. var pending = [];
  63. var transform = function(el) { pending.push(el) };
  64. load("ace.js", function() {
  65. ace.config.loadModule("ace/ext/textarea", function(m) {
  66. transform = function(el) {
  67. if (!el.ace)
  68. el.ace = m.transformTextarea(el, options.ace);
  69. };
  70. pending = pending.forEach(transform);
  71. callback && setTimeout(callback);
  72. });
  73. });
  74. if (options.target)
  75. return transform(options.target);
  76. window.addEventListener("click", function(e) {
  77. if (e.detail == 3 && e.target.localName == "textarea")
  78. transform(e.target);
  79. });
  80. }
  81. // Call the inject function to load the ace files.
  82. var textAce;
  83. inject({
  84. baseUrl: "../../src-noconflict",
  85. target: document.querySelector("textarea")
  86. }, function () {
  87. // Transform the textarea on the page into an ace editor.
  88. textAce = document.querySelector("textarea").ace;
  89. textAce.setDisplaySettings(true);
  90. buildBookmarklet();
  91. });
  92. function buildBookmarklet() {
  93. var injectSrc = inject.toString().split("\n").join("");
  94. injectSrc = injectSrc.replace(/\s+/g, " ");
  95. Function("", injectSrc); // check if injectSrc is still valid js
  96. var options = textAce.getOptions();
  97. options.baseUrl = document.getElementById("srcURL").value;
  98. var els = document.querySelectorAll(".bookmarkletLink");
  99. for (var i = 0; i < els.length; i++)
  100. els[i].href = "javascript:(" + injectSrc + ")(" + JSON.stringify(options) + ")";
  101. }
  102. </script>
  103. </body>
  104. </html>