|
|
@@ -45,24 +45,12 @@ define([], function () {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
-window.UEDITOR_HOME_URL = Config.__CDN__ + "/assets/addons/ueditor/";
|
|
|
require.config({
|
|
|
paths: {
|
|
|
- 'ueditor.config': '../addons/ueditor/ueditor.config',
|
|
|
- 'ueditor': '../addons/ueditor/ueditor.all.min',
|
|
|
- 'ueditor.zh': '../addons/ueditor/i18n/zh-cn/zh-cn',
|
|
|
- 'zeroclipboard': '../addons/ueditor/third-party/zeroclipboard/ZeroClipboard.min',
|
|
|
+ 'summernote': '../addons/summernote/lang/summernote-zh-CN.min'
|
|
|
},
|
|
|
shim: {
|
|
|
- 'ueditor': {
|
|
|
- deps: ['zeroclipboard', 'ueditor.config'],
|
|
|
- exports: 'UE',
|
|
|
- init: function (ZeroClipboard) {
|
|
|
- //导出到全局变量,供ueditor使用
|
|
|
- window.ZeroClipboard = ZeroClipboard;
|
|
|
- },
|
|
|
- },
|
|
|
- 'ueditor.zh': ['ueditor']
|
|
|
+ 'summernote': ['../addons/summernote/js/summernote.min', 'css!../addons/summernote/css/summernote.min.css'],
|
|
|
}
|
|
|
});
|
|
|
require(['form', 'upload'], function (Form, Upload) {
|
|
|
@@ -70,42 +58,103 @@ require(['form', 'upload'], function (Form, Upload) {
|
|
|
Form.events.bindevent = function (form) {
|
|
|
_bindevent.apply(this, [form]);
|
|
|
try {
|
|
|
- //绑定editor事件
|
|
|
- require(['ueditor', 'ueditor.zh'], function (UE, undefined) {
|
|
|
- UE.list = [];
|
|
|
- window.UEDITOR_CONFIG['uploadService'] = function (context, editor) {
|
|
|
- return {
|
|
|
- Upload: () => { return Upload },
|
|
|
- Fast: () => { return Fast },
|
|
|
- }
|
|
|
- };
|
|
|
- $(Config.ueditor.classname || '.editor', form).each(function () {
|
|
|
- var id = $(this).attr("id");
|
|
|
- var name = $(this).attr("name");
|
|
|
- $(this).removeClass('form-control');
|
|
|
- UE.list[id] = UE.getEditor(id, {
|
|
|
- allowDivTransToP: false, //阻止div自动转p标签
|
|
|
- initialFrameWidth: '100%',
|
|
|
- initialFrameHeight: 320,
|
|
|
- autoFloatEnabled: false,
|
|
|
- baiduMapAk: Config.ueditor.baiduMapAk || '', //百度地图api密钥(ak)
|
|
|
- // autoHeightEnabled: true, //自动高度
|
|
|
- zIndex: 90,
|
|
|
- xssFilterRules: false,
|
|
|
- outputXssFilter: false,
|
|
|
- inputXssFilter: false,
|
|
|
- catchRemoteImageEnable: true,
|
|
|
- imageAllowFiles: '',//允许上传的图片格式,编辑器默认[".png", ".jpg", ".jpeg", ".gif", ".bmp"]
|
|
|
+ //绑定summernote事件
|
|
|
+ if ($(Config.summernote.classname || '.editor', form).length > 0) {
|
|
|
+ var selectUrl = typeof Config !== 'undefined' && Config.modulename === 'index' ? 'user/attachment' : 'general/attachment/select';
|
|
|
+ require(['summernote'], function () {
|
|
|
+ var imageButton = function (context) {
|
|
|
+ var ui = $.summernote.ui;
|
|
|
+ var button = ui.button({
|
|
|
+ contents: '<i class="fa fa-file-image-o"/>',
|
|
|
+ tooltip: __('Choose'),
|
|
|
+ click: function () {
|
|
|
+ parent.Fast.api.open(selectUrl + "?element_id=&multiple=true&mimetype=image/", __('Choose'), {
|
|
|
+ callback: function (data) {
|
|
|
+ var urlArr = data.url.split(/\,/);
|
|
|
+ $.each(urlArr, function () {
|
|
|
+ var url = Fast.api.cdnurl(this, true);
|
|
|
+ context.invoke('editor.insertImage', url);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return button.render();
|
|
|
+ };
|
|
|
+ var attachmentButton = function (context) {
|
|
|
+ var ui = $.summernote.ui;
|
|
|
+ var button = ui.button({
|
|
|
+ contents: '<i class="fa fa-file"/>',
|
|
|
+ tooltip: __('Choose'),
|
|
|
+ click: function () {
|
|
|
+ parent.Fast.api.open(selectUrl + "?element_id=&multiple=true&mimetype=*", __('Choose'), {
|
|
|
+ callback: function (data) {
|
|
|
+ var urlArr = data.url.split(/\,/);
|
|
|
+ $.each(urlArr, function () {
|
|
|
+ var url = Fast.api.cdnurl(this, true);
|
|
|
+ var node = $("<a href='" + url + "'>" + url + "</a>");
|
|
|
+ context.invoke('insertNode', node[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return button.render();
|
|
|
+ };
|
|
|
+
|
|
|
+ $(Config.summernote.classname || '.editor', form).each(function () {
|
|
|
+ $(this).summernote($.extend(true, {}, {
|
|
|
+ height: isNaN(Config.summernote.height) ? null : parseInt(Config.summernote.height),
|
|
|
+ minHeight: parseInt(Config.summernote.minHeight || 250),
|
|
|
+ toolbar: Config.summernote.toolbar,
|
|
|
+ followingToolbar: parseInt(Config.summernote.followingToolbar),
|
|
|
+ placeholder: Config.summernote.placeholder || '',
|
|
|
+ airMode: parseInt(Config.summernote.airMode) || false,
|
|
|
+ lang: 'zh-CN',
|
|
|
+ fontNames: [
|
|
|
+ 'Arial', 'Arial Black', 'Serif', 'Sans', 'Courier',
|
|
|
+ 'Courier New', 'Comic Sans MS', 'Helvetica', 'Impact', 'Lucida Grande',
|
|
|
+ "Open Sans", "Hiragino Sans GB", "Microsoft YaHei",
|
|
|
+ '微软雅黑', '宋体', '黑体', '仿宋', '楷体', '幼圆',
|
|
|
+ ],
|
|
|
+ fontNamesIgnoreCheck: [
|
|
|
+ "Open Sans", "Microsoft YaHei",
|
|
|
+ '微软雅黑', '宋体', '黑体', '仿宋', '楷体', '幼圆'
|
|
|
+ ],
|
|
|
+ buttons: {
|
|
|
+ image: imageButton,
|
|
|
+ attachment: attachmentButton,
|
|
|
+ },
|
|
|
+ dialogsInBody: true,
|
|
|
+ callbacks: {
|
|
|
+ onChange: function (contents) {
|
|
|
+ $(this).val(contents);
|
|
|
+ $(this).trigger('change');
|
|
|
+ },
|
|
|
+ onInit: function () {
|
|
|
+ },
|
|
|
+ onImageUpload: function (files) {
|
|
|
+ var that = this;
|
|
|
+ //依次上传图片
|
|
|
+ for (var i = 0; i < files.length; i++) {
|
|
|
+ Upload.api.send(files[i], function (data) {
|
|
|
+ var url = Fast.api.cdnurl(data.url, true);
|
|
|
+ $(that).summernote("insertImage", url, 'filename');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, $(this).data("summernote-options") || {}));
|
|
|
});
|
|
|
- UE.list[id].addListener("contentChange", function () {
|
|
|
- $('#' + id).val(this.getContent());
|
|
|
- $('textarea[name="' + name + '"]').val(this.getContent());
|
|
|
- })
|
|
|
});
|
|
|
- })
|
|
|
+ }
|
|
|
} catch (e) {
|
|
|
- console.log('绑定editor事件', e)
|
|
|
+
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
+ };
|
|
|
});
|
|
|
+
|
|
|
});
|