bootstrapBase.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. require.config({
  2. paths: {
  3. 'tinymce': '../addons/tinymce/js/tinymce/tinymce.min'
  4. },
  5. });
  6. require(['form', 'upload'], function (Form, Upload) {
  7. var _bindevent = Form.events.bindevent;
  8. Form.events.bindevent = function (form) {
  9. _bindevent.apply(this, [form]);
  10. try {
  11. //绑定summernote事件
  12. if ($(".tinymce,.editor", form).size() > 0) {
  13. require(['tinymce'], function () {
  14. var init = {
  15. selector: ".tinymce,.editor",//容器可以是id也可以是class
  16. language: '{language}',//语言
  17. theme: 'silver',//主体默认主题
  18. plugins: ['{plugins}'],//所含插件
  19. content_style : '{content_style}',//编辑器样式只对编辑器试图有效不会提交到html中
  20. toolbar: '{toolbar}',//工具栏
  21. file_picker_types: 'image,media',//文件上传支持类型:file,image,media
  22. //图像上传处理
  23. convert_urls:false,//关闭url自动检测
  24. images_upload_handler: function (blobInfo, success, failure) {
  25. Upload.api.send(blobInfo.blob(), function (data) {
  26. var url = Fast.api.cdnurl(data.url);
  27. success( url);
  28. return;
  29. },function (data,ret) {
  30. Layer && Layer.closeAll('dialog');
  31. failure(ret.msg);
  32. return;
  33. });
  34. },
  35. image_default_size:'{image_default_size}',//图片添加成功后的默认宽高 格式:{width:"",height:''} 允许是百分比或像素
  36. media_default_size:'{media_default_size}',//音/视频添加成功后的默认宽高 格式:{width:"",height:''} 允许是百分比或像素
  37. browser_spellcheck: '{browser_spellcheck}',//浏览器检查拼写
  38. spellchecker_callback: function(method, text, success, failure) {
  39. var words = text.match(this.getWordCharPattern());
  40. if (method == "spellcheck") {
  41. var suggestions = {};
  42. for (var i = 0; i < words.length; i++) {
  43. suggestions[words[i]] = ["First", "Second"];
  44. }
  45. success(suggestions);
  46. }
  47. },
  48. setup:function (editor) {
  49. editor.on('change',function () {
  50. editor.save();
  51. $(editor.getElement()).trigger("input");
  52. });
  53. }
  54. };
  55. if('{up_video}'){
  56. //文件上传处理
  57. init.file_picker_callback = function(callback, value, meta) {
  58. //为不同插件指定文件类型
  59. switch(meta.filetype){
  60. case 'image':
  61. filetype='image/*';
  62. break;
  63. case 'media':
  64. filetype='audio/*,video/*';
  65. break;
  66. case 'file':
  67. default:
  68. }
  69. //模拟出一个input用于添加本地文件
  70. var input = document.createElement('input');
  71. input.setAttribute('type', 'file');
  72. input.setAttribute('accept', filetype);
  73. input.click();
  74. input.onchange = function() {
  75. Upload.api.send(this.files[0], function (data) {
  76. var url = Fast.api.cdnurl(data.url);
  77. callback(url);
  78. return;
  79. },function (data,ret) {
  80. Layer && Layer.closeAll('dialog');
  81. alert(ret.msg);
  82. return;
  83. });
  84. };
  85. };
  86. }
  87. tinymce.init(init);
  88. $(document).on("click", "{subDom}", function () {
  89. tinymce.triggerSave();
  90. });
  91. });
  92. }
  93. } catch (e) {
  94. }
  95. };
  96. });