123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- window.UMEDITOR_HOME_URL = Config.__CDN__ + "/assets/addons/umeditor/";
- require.config({
- paths: {
- 'umeditor': '../addons/umeditor/umeditor.min',
- 'umeditor.config': '../addons/umeditor/umeditor.config',
- 'umeditor.lang': '../addons/umeditor/lang/zh-cn/zh-cn',
- },
- shim: {
- 'umeditor': {
- deps: [
- 'umeditor.config',
- 'css!../addons/umeditor/themes/default/css/umeditor.min.css'
- ],
- exports: 'UM',
- },
- 'umeditor.lang': ['umeditor']
- }
- });
- require(['form', 'upload'], function (Form, Upload) {
- //监听上传文本框的事件
- $(document).on("edui.file.change", ".edui-image-file", function (e, up, me, input, callback) {
- for (var i = 0; i < this.files.length; i++) {
- Upload.api.send(this.files[i], function (data) {
- var url = data.url;
- me.uploadComplete(JSON.stringify({url: url, state: "SUCCESS"}));
- });
- }
- up.updateInput(input);
- me.toggleMask("Loading....");
- callback && callback();
- });
- var _bindevent = Form.events.bindevent;
- Form.events.bindevent = function (form) {
- _bindevent.apply(this, [form]);
- require(['umeditor', 'umeditor.lang'], function (UME, undefined) {
- //重写编辑器加载
- UME.plugins['autoupload'] = function () {
- var me = this;
- me.setOpt('pasteImageEnabled', true);
- me.setOpt('dropFileEnabled', true);
- var sendAndInsertImage = function (file, editor) {
- try {
- Upload.api.send(file, function (data) {
- var url = Fast.api.cdnurl(data.url, true);
- editor.execCommand('insertimage', {
- src: url,
- _src: url
- });
- });
- } catch (er) {
- }
- };
- function getPasteImage(e) {
- return e.clipboardData && e.clipboardData.items && e.clipboardData.items.length == 1 && /^image\//.test(e.clipboardData.items[0].type) ? e.clipboardData.items : null;
- }
- function getDropImage(e) {
- return e.dataTransfer && e.dataTransfer.files ? e.dataTransfer.files : null;
- }
- me.addListener('ready', function () {
- if (window.FormData && window.FileReader) {
- var autoUploadHandler = function (e) {
- var hasImg = false,
- items;
- //获取粘贴板文件列表或者拖放文件列表
- items = e.type == 'paste' ? getPasteImage(e.originalEvent) : getDropImage(e.originalEvent);
- if (items) {
- var len = items.length,
- file;
- while (len--) {
- file = items[len];
- if (file.getAsFile)
- file = file.getAsFile();
- if (file && file.size > 0 && /image\/\w+/i.test(file.type)) {
- sendAndInsertImage(file, me);
- hasImg = true;
- }
- }
- if (hasImg)
- return false;
- }
- };
- me.getOpt('pasteImageEnabled') && me.$body.on('paste', autoUploadHandler);
- me.getOpt('dropFileEnabled') && me.$body.on('drop', autoUploadHandler);
- //取消拖放图片时出现的文字光标位置提示
- me.$body.on('dragover', function (e) {
- if (e.originalEvent.dataTransfer.types[0] == 'Files') {
- return false;
- }
- });
- }
- });
- };
- $.extend(window.UMEDITOR_CONFIG.whiteList, {
- div: ['style', 'class', 'id', 'data-tpl', 'data-source', 'data-id'],
- span: ['style', 'class', 'id', 'data-id']
- });
- $(Config.umeditor.classname || '.editor', form).each(function () {
- var id = $(this).attr("id");
- $(this).removeClass('form-control');
- var options = $(this).data("umeditor-options");
- UME.list[id] = UME.getEditor(id, $.extend(true, {}, {
- initialFrameWidth: '100%',
- zIndex: 90,
- autoHeightEnabled: true,
- initialFrameHeight: 300,
- xssFilterRules: false,
- outputXssFilter: false,
- inputXssFilter: false,
- autoFloatEnabled: false,
- imageUrl: '',
- imagePath: Config.upload.cdnurl,
- imageUploadCallback: function (file, fn) {
- var me = this;
- Upload.api.send(file, function (data) {
- var url = data.url;
- fn && fn.call(me, url, data);
- });
- }
- }, options || {}));
- });
- });
- }
- });
|