use-requirejs.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Using require.js - Editor.md examples</title>
  6. <link rel="stylesheet" href="css/style.css" />
  7. <link rel="stylesheet" href="../lib/codemirror/codemirror.min.css" />
  8. <!-- <link rel="stylesheet" href="../lib/codemirror/addon/fold/foldgutter.css" /> -->
  9. <link rel="stylesheet" href="../css/editormd.min.css" />
  10. <link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" />
  11. </head>
  12. <body>
  13. <div id="layout">
  14. <header>
  15. <h1>Using require.js</h1>
  16. <ul style="margin: 10px 0 0 18px;">
  17. <li>Enable HTML tags decode</li>
  18. <li>Enable TeX, Flowchart, Sequence Diagram, Emoji, FontAwesome, Task lists</li>
  19. <li>Enable Image upload</li>
  20. <li>Enable [TOCM], Search Replace, Code fold</li>
  21. </ul>
  22. </header>
  23. <div class="btns">
  24. <button id="show-btn">Show editor</button>
  25. <button id="hide-btn">Hide editor</button>
  26. <button id="get-md-btn">Get Markdown</button>
  27. <button id="get-html-btn">Get HTML</button>
  28. <button id="watch-btn">Watch</button>
  29. <button id="unwatch-btn">Unwatch</button>
  30. <button id="preview-btn">Preview HTML (Press Shift + ESC cancel)</button>
  31. <button id="fullscreen-btn">Fullscreen (Press ESC cancel)</button>
  32. <button id="show-toolbar-btn">Show toolbar</button>
  33. <button id="close-toolbar-btn">Hide toolbar</button>
  34. <button id="toc-menu-btn">ToC Dropdown menu</button>
  35. <button id="toc-default-btn">ToC default</button>
  36. </div>
  37. <div id="test-editormd"></div>
  38. </div>
  39. <script src="js/require.min.js"></script>
  40. <script type="text/javascript">
  41. requirejs.config({
  42. baseUrl: "../lib/",
  43. paths: {
  44. jquery : "../examples/js/jquery.min",
  45. marked : "marked.min",
  46. prettify : "prettify.min",
  47. raphael : "raphael.min",
  48. underscore : "underscore.min",
  49. flowchart : "flowchart.min",
  50. jqueryflowchart : "jquery.flowchart.min",
  51. sequenceDiagram : "sequence-diagram.min",
  52. katex : "//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min",
  53. editormd : "../editormd.amd" // Using Editor.md amd version for Require.js
  54. },
  55. waitSeconds: 30
  56. });
  57. var deps = [
  58. "editormd",
  59. "../languages/en",
  60. "../plugins/link-dialog/link-dialog",
  61. "../plugins/reference-link-dialog/reference-link-dialog",
  62. "../plugins/image-dialog/image-dialog",
  63. "../plugins/code-block-dialog/code-block-dialog",
  64. "../plugins/table-dialog/table-dialog",
  65. "../plugins/emoji-dialog/emoji-dialog",
  66. "../plugins/goto-line-dialog/goto-line-dialog",
  67. "../plugins/help-dialog/help-dialog",
  68. "../plugins/html-entities-dialog/html-entities-dialog",
  69. "../plugins/preformatted-text-dialog/preformatted-text-dialog"
  70. ];
  71. var testEditor;
  72. require(deps, function(editormd) {
  73. // if enable codeFold
  74. // or <link rel="stylesheet" href="../lib/codemirror/addon/fold/foldgutter.css" />
  75. editormd.loadCSS("../lib/codemirror/addon/fold/foldgutter");
  76. $.get('test.md', function(md) {
  77. testEditor = editormd("test-editormd", {
  78. width: "90%",
  79. height: 640,
  80. path : '../lib/',
  81. markdown : md,
  82. codeFold : true,
  83. searchReplace : true,
  84. saveHTMLToTextarea : true, // 保存HTML到Textarea
  85. htmlDecode : "style,script,iframe|on*", // 开启HTML标签解析,为了安全性,默认不开启
  86. emoji : true,
  87. taskList : true,
  88. tex : true,
  89. tocm : true, // Using [TOCM]
  90. autoLoadModules : false,
  91. previewCodeHighlight : true,
  92. flowChart : true,
  93. sequenceDiagram : true,
  94. //dialogLockScreen : false, // 设置弹出层对话框不锁屏,全局通用,默认为true
  95. //dialogShowMask : false, // 设置弹出层对话框显示透明遮罩层,全局通用,默认为true
  96. //dialogDraggable : false, // 设置弹出层对话框不可拖动,全局通用,默认为true
  97. //dialogMaskOpacity : 0.4, // 设置透明遮罩层的透明度,全局通用,默认值为0.1
  98. //dialogMaskBgColor : "#000", // 设置透明遮罩层的背景颜色,全局通用,默认为#fff
  99. imageUpload : true,
  100. imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
  101. imageUploadURL : "./php/upload.php",
  102. onload : function() {
  103. console.log('onload', this);
  104. //this.fullscreen();
  105. //this.unwatch();
  106. //this.watch().fullscreen();
  107. //this.setMarkdown("#PHP");
  108. //this.width("100%");
  109. //this.height(480);
  110. //this.resize("100%", 640);
  111. }
  112. });
  113. });
  114. $("#show-btn").bind('click', function(){
  115. testEditor.show();
  116. });
  117. $("#hide-btn").bind('click', function(){
  118. testEditor.hide();
  119. });
  120. $("#get-md-btn").bind('click', function(){
  121. alert(testEditor.getMarkdown());
  122. });
  123. $("#get-html-btn").bind('click', function() {
  124. alert(testEditor.getHTML());
  125. });
  126. $("#watch-btn").bind('click', function() {
  127. testEditor.watch();
  128. });
  129. $("#unwatch-btn").bind('click', function() {
  130. testEditor.unwatch();
  131. });
  132. $("#preview-btn").bind('click', function() {
  133. testEditor.previewing();
  134. });
  135. $("#fullscreen-btn").bind('click', function() {
  136. testEditor.fullscreen();
  137. });
  138. $("#show-toolbar-btn").bind('click', function() {
  139. testEditor.showToolbar();
  140. });
  141. $("#close-toolbar-btn").bind('click', function() {
  142. testEditor.hideToolbar();
  143. });
  144. $("#toc-menu-btn").click(function(){
  145. testEditor.config({
  146. tocDropdown : true,
  147. tocTitle : "目录 Table of Contents",
  148. });
  149. });
  150. $("#toc-default-btn").click(function() {
  151. testEditor.config("tocDropdown", false);
  152. });
  153. });
  154. </script>
  155. </body>
  156. </html>