editormd.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. layui.define([], function (exports) {
  2. var MOD_NAME = 'editormd';
  3. var modFile = layui.cache.modules['editormd'];
  4. var modPath = modFile.substr(0, modFile.lastIndexOf('.'));
  5. var plugin_filename = 'editormd.min.js'//插件路径
  6. var settings = {
  7. markdown: '',
  8. path: modPath + '/lib/',
  9. placeholder: "请输入内容...",
  10. height: window.innerHeight / 2,
  11. htmlDecode: "style,script,iframe",
  12. imageUpload: true,
  13. imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
  14. imageUploadURL: "/admin/api/upload/sourse/editormd",
  15. saveHTMLToTextarea: true,//保存html到textarea
  16. toolbarIcons: function () {
  17. return [
  18. "undo", "redo", "|",
  19. "bold", "del", "italic", "quote", "ucwords", "uppercase", "lowercase", "|",
  20. "h1", "h2", "h3", "h4", "h5", "h6", "|",
  21. "list-ul", "list-ol", "hr", "|",
  22. "link", "reference-link", "image", "code", "preformatted-text", "code-block", "table", "datetime", "html-entities", "pagebreak", "|",
  23. "goto-line", "watch", "preview", "fullscreen", "clear", "search", "|",
  24. "help"
  25. ];
  26. },
  27. lang: {
  28. dialog: {
  29. preformattedText: { placeholder: "此处编写代码..." },
  30. codeBlock: { placeholder: "此处编写代码...." }
  31. }
  32. },
  33. onfullscreen: function () {
  34. this.editor.css("z-index", 120);
  35. },
  36. onfullscreenExit: function () {
  37. this.editor.css({
  38. zIndex: 10,
  39. border: "none",
  40. });
  41. this.resize();
  42. },
  43. onload: function () {
  44. initPasteDragImg(this); //必须
  45. }
  46. };
  47. var editor = {
  48. render: function (editorId, options) {
  49. loadScript();
  50. var opts = $.extend({}, settings, options);
  51. return editormd(editorId, opts);
  52. }
  53. }
  54. function loadScript() {
  55. if (typeof editormd == 'undefined') {
  56. $.ajax({ //获取插件
  57. url: modPath + '/' + plugin_filename,
  58. dataType: 'script',
  59. cache: true,
  60. async: false,
  61. });
  62. $.ajax({ //获取插件
  63. url: modPath + '/paste.upload.img.js',
  64. dataType: 'script',
  65. cache: true,
  66. async: false,
  67. });
  68. layui.link(modPath + '/css/editormd.min.css');
  69. layui.link(modPath + '/css/editormd.preview.min.css');
  70. }
  71. }
  72. exports(MOD_NAME, editor);
  73. });