admin.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. require('./bootstrap');
  2. require("inline-attachment/src/inline-attachment.js");
  3. require("inline-attachment/src/codemirror-4.inline-attachment.js");
  4. window.markdown_editor = function () {
  5. window.SimpleMDE = require('simplemde');
  6. // Most options demonstrate the non-default behavior
  7. var unique_id = $('#slug').val() ? $('#slug').val() : 'markdown';
  8. var markdown = new SimpleMDE({
  9. autofocus: true,
  10. autosave: {
  11. enabled: true,
  12. uniqueId: unique_id,
  13. delay: 1000
  14. },
  15. element: document.getElementById("markdown"),
  16. insertTexts: {
  17. horizontalRule: ["", "\n\n-----\n\n"],
  18. image: ["![](https://", ")"],
  19. link: ["[", "](https://)"],
  20. table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"],
  21. },
  22. placeholder: "Type here...",
  23. spellChecker: false,
  24. renderingConfig: {
  25. codeSyntaxHighlighting: true
  26. },
  27. showIcons: ["code", "horizontal-rule", "table", "strikethrough", "heading-1", "heading-2", "heading-3"],
  28. toolbar: [
  29. {
  30. name: "bold",
  31. action: SimpleMDE.toggleBold,
  32. className: "fa fa-bold",
  33. title: "Bold"
  34. },
  35. {
  36. name: "bold",
  37. action: SimpleMDE.toggleItalic,
  38. className: "fa fa-italic",
  39. title: "Italic"
  40. },
  41. {
  42. name: "strikethrough",
  43. action: SimpleMDE.toggleStrikethrough,
  44. className: "fa fa-strikethrough",
  45. title: "Strikethrough"
  46. },
  47. '|',
  48. {
  49. name: "heading",
  50. action: SimpleMDE.toggleHeadingSmaller,
  51. className: "fa fa-header",
  52. title: "Heading"
  53. },
  54. {
  55. name: "heading-1",
  56. action: SimpleMDE.toggleHeading1,
  57. className: "fa fa-header fa-header-x fa-header-1",
  58. title: "H1"
  59. },
  60. {
  61. name: "heading-2",
  62. action: SimpleMDE.toggleHeading2,
  63. className: "fa fa-header fa-header-x fa-header-2",
  64. title: "H2"
  65. },
  66. {
  67. name: "heading-3",
  68. action: SimpleMDE.toggleHeading1,
  69. className: "fa fa-header fa-header-x fa-header-3",
  70. title: "H3"
  71. },
  72. '|',
  73. {
  74. name: "code",
  75. action: SimpleMDE.toggleCodeBlock,
  76. className: "fa fa-code",
  77. title: "Code"
  78. },
  79. {
  80. name: "quote",
  81. action: SimpleMDE.toggleBlockquote,
  82. className: "fa fa-quote-left",
  83. title: "Quote"
  84. },
  85. {
  86. name: "unordered-list",
  87. action: SimpleMDE.toggleUnorderedList,
  88. className: "fa fa-list-ul",
  89. title: "Generic List"
  90. },
  91. {
  92. name: "ordered-list",
  93. action: SimpleMDE.toggleOrderedList,
  94. className: "fa fa-list-ol",
  95. title: "Numbered List"
  96. },
  97. {
  98. name: "horizontal-rule",
  99. action: SimpleMDE.drawHorizontalRule,
  100. className: "fa fa-minus",
  101. title: "Insert Horizontal Line"
  102. },
  103. '|',
  104. {
  105. name: "link",
  106. action: SimpleMDE.drawLink,
  107. className: "fa fa-link",
  108. title: "Create Link"
  109. },
  110. {
  111. name: "image",
  112. action: SimpleMDE.drawImage,
  113. className: "fa fa-picture-o",
  114. title: "Insert Image"
  115. },
  116. {
  117. name: "table",
  118. action: SimpleMDE.drawTable,
  119. className: "fa fa-table",
  120. title: "Insert Table"
  121. },
  122. '|',
  123. {
  124. name: "preview",
  125. action: SimpleMDE.togglePreview,
  126. className: "fa fa-eye no-disable",
  127. title: "Toggle Preview"
  128. },
  129. {
  130. name: "side-by-side",
  131. action: SimpleMDE.toggleSideBySide,
  132. className: "fa fa-columns no-disable no-mobile",
  133. title: "Toggle Side by Side"
  134. },
  135. {
  136. name: "fullscreen",
  137. action: SimpleMDE.toggleFullScreen,
  138. className: "fa fa-arrows-alt no-disable no-mobile",
  139. title: "Toggle Fullscreen"
  140. },
  141. {
  142. name: "guide",
  143. action: function customFunction(editor) {
  144. window.open("https://vienblog.com/markdown-yu-fa")
  145. },
  146. className: "fa fa-question-circle",
  147. title: "Help"
  148. }
  149. ]
  150. });
  151. markdown.codemirror.on("change", function () {
  152. var html = markdown.value();
  153. $('input[name="markdown"]').val(html);
  154. });
  155. var inlineAttachmentConfig = {
  156. uploadUrl: '/admin/upload/image/article',
  157. extraHeaders: {
  158. 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
  159. }
  160. };
  161. inlineAttachment.editors.codemirror4.attach(markdown.codemirror,
  162. inlineAttachmentConfig);
  163. }