aboutsummaryrefslogtreecommitdiff
path: root/js/index.html
blob: 3c75b5cdaf5fb24f6dccd5da3e780bca5303f2f7 (plain)
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>stmd.js demo</title>
  6. <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
  7. <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
  8. <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  9. <script src="stmd.js"></script>
  10. <script type="text/javascript">
  11. var writer = new stmd.HtmlRenderer();
  12. var reader = new stmd.DocParser();
  13. $(document).ready(function() {
  14. $(".timing").hide();
  15. var timer;
  16. var x;
  17. var parsed;
  18. var render = function() {
  19. if (parsed === undefined) {
  20. return;
  21. }
  22. var startTime = new Date().getTime();
  23. var result = writer.renderBlock(parsed);
  24. var endTime = new Date().getTime();
  25. var renderTime = endTime - startTime;
  26. // $("#html").text(result);
  27. $("#preview").html(result);
  28. $("#html").text(result);
  29. $("#rendertime").text(renderTime);
  30. };
  31. var parseAndRender = function () {
  32. if (x) { x.abort() } // If there is an existing XHR, abort it.
  33. clearTimeout(timer); // Clear the timer so we don't end up with dupes.
  34. timer = setTimeout(function() { // assign timer a new timeout
  35. var startTime = new Date().getTime();
  36. parsed = reader.parse($("#text").val());
  37. var endTime = new Date().getTime();
  38. var parseTime = endTime - startTime;
  39. $("#parsetime").text(parseTime);
  40. $(".timing").show();
  41. /*
  42. var warnings = parsed.warnings;
  43. $("#warnings").html('');
  44. for (i=0; i < warnings.length; i++) {
  45. var w = warnings[i];
  46. var warning = $("#warnings").append('<li></li>');
  47. $("#warnings li").last().text('Line ' + w.line + ' column ' + w.column + ': ' + w.message);
  48. }
  49. */
  50. render();
  51. }, 0); // ms delay
  52. };
  53. $("#text").change(parseAndRender);
  54. $(".option").change(render);
  55. });
  56. </script>
  57. <style type="text/css">
  58. textarea#text { height: 400px; width: 95%; font-family: monospace; font-size: 92%; }
  59. pre code#html { font-size: 92%; font-family: monospace; }
  60. pre#htmlpre { height: 400px; width: 95%; overflow: scroll; }
  61. div#preview { height: 400px; overflow: scroll; }
  62. div.row { margin-top: 1em; }
  63. blockquote { font-size: 100%; }
  64. footer { color: #555; text-align: center; margin: 1em; }
  65. pre { display: block; padding: 0.5em; color: #333; background: #f8f8ff }
  66. #warnings li { color: red; font-weight: bold; }
  67. label { padding-left: 1em; padding-top: 0; padding-bottom: 0; }
  68. p.timing { color: red; }
  69. span.timing { font-weight: bold; }
  70. span.timing { font-weight: bold; }
  71. </style>
  72. </head>
  73. <body>
  74. <div class="container">
  75. <div class="row">
  76. <div class="col-md-6">
  77. <h1>stmd.js dingus</h1>
  78. </div>
  79. <div class="col-md-3">
  80. <ul class="nav nav-tabs" role="tablist">
  81. <li class="active"><a href="#preview" role="tab" data-toggle="tab">Preview</a></li>
  82. <li><a href="#result" role="tab" data-toggle="tab">HTML</a></li>
  83. </ul>
  84. </div>
  85. <div class="col-md-3">
  86. <p class="timing">Parsed in <span class="timing" id="parsetime"></span> milliseconds.<br/>
  87. Rendered in <span class="timing" id="rendertime"></span> milliseconds.</p>
  88. </div>
  89. </div>
  90. <div class="row">
  91. <div class="col-md-6">
  92. <textarea id="text"></textarea>
  93. <ul id="warnings"></ul>
  94. </div>
  95. <div class="col-md-6">
  96. <div class="tab-content">
  97. <div id="preview" class="tab-pane active">
  98. </div>
  99. <div id="result" class="tab-pane">
  100. <pre id="htmlpre"><code id="html"></code></pre>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. </body>
  107. </html>