tinymce.js 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. layui.define([], function (exports) {
  2. var MOD_NAME = 'tinymce';
  3. var modFile = layui.cache.modules['tinymce'];
  4. var modPath = modFile.substr(0, modFile.lastIndexOf('.'));
  5. var plugin_filename = 'tinymce.min.js'//插件名称
  6. var settings = {
  7. base_url:modPath,
  8. images_upload_url: '/admin/api/upload/sourse/tinymce',//图片上传接口
  9. images_upload_credentials:true,
  10. placeholder: '请输入内容...',
  11. language: 'zh_CN',//语言
  12. suffix: '.min',
  13. selector: '#gouguedit',
  14. quickbars_insert_toolbar:'',
  15. quickbars_selection_toolbar: 'cut copy | bold italic underline strikethrough ',
  16. plugins: 'code quickbars print preview searchreplace autolink fullscreen image link media codesample table charmap hr advlist lists wordcount imagetools paste',
  17. toolbar: 'code undo redo | forecolor backcolor bold italic underline strikethrough removeformat | alignleft aligncenter alignright alignjustify outdent indent | bullist numlist table blockquote link image media codesample | formatselect fontselect fontsizeselect',
  18. resize: false,
  19. elementpath: false,
  20. branding: false,
  21. statusbar: false,
  22. convert_urls: false,// 附件路径无需要转换为相对路径。
  23. contextmenu_never_use_native: true,
  24. paste_data_images: true,
  25. menubar: 'file edit insert format table',
  26. menu: {
  27. file: { title: '文件', items: 'preview fullscreen | wordcount' },
  28. edit: { title: '编辑', items: 'undo redo | cut copy paste pastetext selectall | searchreplace' },
  29. format: {
  30. title: '格式',
  31. items: 'bold italic underline strikethrough superscript subscript | formats | forecolor backcolor | removeformat'
  32. },
  33. table: { title: '表格', items: 'inserttable tableprops deletetable | cell row column' },
  34. },
  35. codesample_languages: [
  36. {text: 'HTML', value: 'html'},
  37. {text: 'JavaScript', value: 'javascript'},
  38. {text: 'CSS', value: 'css'},
  39. {text: 'PHP', value: 'php'},
  40. {text: 'Java', value: 'java'},
  41. {text: 'Shell', value: 'shell'},
  42. {text: 'SQL', value: 'sql'},
  43. {text: 'JOSN', value: 'json'},
  44. {text: 'Python', value: 'python'},
  45. {text: 'XML', value: 'xml'},
  46. {text: 'Golang', value: 'go'},
  47. {text: 'Objective-c', value: 'objective-c'},
  48. ],
  49. fontsize_formats: '12px 14px 16px 18px 24px 36px 48px 56px 72px',
  50. font_formats: '微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;苹果苹方=PingFang SC,Microsoft YaHei,sans-serif;宋体=simsun,serif;仿宋体=FangSong,serif;黑体=SimHei,sans-serif;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats;知乎配置=BlinkMacSystemFont, Helvetica Neue, PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, WenQuanYi Micro Hei, sans-serif;小米配置=Helvetica Neue,Helvetica,Arial,Microsoft Yahei,Hiragino Sans GB,Heiti SC,WenQuanYi Micro Hei,sans-serif',
  51. setup: function(editor) {
  52. console.log("ID为: " + editor.id + " 的编辑器即将初始化.");
  53. },
  54. init_instance_callback : function(editor) {
  55. console.log("ID为: " + editor.id + " 的编辑器已初始化完成.");
  56. }
  57. };
  58. var editor = {
  59. render: function (options) {
  60. loadScript();
  61. var opts = $.extend({}, settings, options), edit = this.get(opts.elem);
  62. if (edit) {
  63. edit.destroy();
  64. }
  65. tinymce.init(opts);
  66. return this.get(opts.elem);
  67. },
  68. // 获取ID对应的编辑器对象
  69. get: function (elem) {
  70. loadScript();
  71. if (elem && /^#|\./.test(elem)) {
  72. var id = elem.substr(1);
  73. var edit = tinymce.editors[id];
  74. return edit;
  75. } else {
  76. return false;
  77. }
  78. }
  79. }
  80. function loadScript() {
  81. if (typeof tinymce == 'undefined') {
  82. $.ajax({//获取插件
  83. url: modPath + '/' + plugin_filename,
  84. dataType: 'script',
  85. cache: true,
  86. async: false,
  87. });
  88. }
  89. }
  90. exports(MOD_NAME, editor);
  91. });