标签:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String contextPath = request.getContextPath();%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="ueditor/ueditor.config.js" type="text/javascript" charset="utf-8"></script>
<script src="ueditor/ueditor.config.js/ueditor.all.min.js" type="text/javascript" charset="utf-8"></script>
<!-- 当然还要引入jquery -->
<script type="text/javascript">
var editor;
var _editor;
$(function() {
editor = UE.getEditor(‘myEditor‘, {
initialFrameWidth: 800,
initialFrameHeight: 300,
});
//重新实例化一个编辑器,防止在上面的editor编辑器中显示上传的图片或者文件
_editor = UE.getEditor(‘upload_ue‘);
_editor.ready(function () {
//设置编辑器不可用
//_editor.setDisabled();
//隐藏编辑器,因为不会用到这个编辑器实例,所以要隐藏
_editor.hide();
//侦听图片上传
_editor.addListener(‘beforeInsertImage‘, function (t, arg) {
//将地址赋值给相应的input,只去第一张图片的路径
$("#picture").attr("value", arg[0].src);
//图片预览
$("#preview").attr("src", arg[0].src);
})
//侦听文件上传,取上传文件列表中第一个上传的文件的路径
_editor.addListener(‘afterUpfile‘, function (t, arg) {
$("#file").attr("value", _editor.options.filePath + arg[0].url);
})
});
});
//弹出图片上传的对话框
function upImage() {
var myImage = _editor.getDialog("insertimage");
myImage.open();
}
//弹出文件上传的对话框
function upFiles() {
var myFiles = _editor.getDialog("attachment");
myFiles.open();
}
</script>
</head>
<body>
<script type="text/plain" id="myEditor"></script>
<script type="text/plain" id="upload_ue"></script>
调用的页面:
<input type="text" id="picture" name="cover" /><a href="javascript:void(0);" onclick="upImage();">上传图片</a>
<input type="text" id="file" /><a href="javascript:void(0);" onclick="upFiles();">上传文件</a>
</body>
</html>
var _editor = UE.getEditor(‘upload_ue1‘);
_editor.ready(function () {
//_editor.setDisabled();
_editor.hide();
_editor.addListener(‘beforeInsertImage‘, function (t, arg) {
$("#picture").attr("value", arg[0].src);
});
//侦听文件上传,取上传文件列表中第一个上传的文件的路径
_editor.addListener(‘afterUpfile‘, function (t, arg) {
$("#file").val("value", _editor.options.filePath + arg[0].url);
})
});
function upImage() {
var myImage = _editor.getDialog("insertimage");
myImage.open();
}
function upFiles() {
var myFiles = _editor.getDialog("attachment");
myFiles.open();
}
1 图片上传无返回值
_editor.setDisabled(); 这行代码删除
2 上传附件没有反应
因为插件里面不存在afterUpfile回调,只存在 beforeinsertimage这个回调
if(me.fireEvent(‘beforeinsertimage‘, opt) === true){
return;
}
修改代码,找到
// plugins/insertfile.js
/**
* 插入附件
*/
UE.plugin.register(‘insertfile‘, function (){
var me = this;
function getFileIcon(url){
var ext = url.substr(url.lastIndexOf(‘.‘) + 1).toLowerCase(),
maps = {
"rar":"icon_rar.gif",
"zip":"icon_rar.gif",
"tar":"icon_rar.gif",
"gz":"icon_rar.gif",
"bz2":"icon_rar.gif",
"doc":"icon_doc.gif",
"docx":"icon_doc.gif",
"pdf":"icon_pdf.gif",
"mp3":"icon_mp3.gif",
"xls":"icon_xls.gif",
"chm":"icon_chm.gif",
"ppt":"icon_ppt.gif",
"pptx":"icon_ppt.gif",
"avi":"icon_mv.gif",
"rmvb":"icon_mv.gif",
"wmv":"icon_mv.gif",
"flv":"icon_mv.gif",
"swf":"icon_mv.gif",
"rm":"icon_mv.gif",
"exe":"icon_exe.gif",
"psd":"icon_psd.gif",
"txt":"icon_txt.gif",
"jpg":"icon_jpg.gif",
"png":"icon_jpg.gif",
"jpeg":"icon_jpg.gif",
"gif":"icon_jpg.gif",
"ico":"icon_jpg.gif",
"bmp":"icon_jpg.gif"
};
return maps[ext] ? maps[ext]:maps[‘txt‘];
}
return {
commands:{
‘insertfile‘: {
execCommand: function (command, filelist){
filelist = utils.isArray(filelist) ? filelist : [filelist];
var i, item, icon, title,
html = ‘‘,
URL = me.getOpt(‘UEDITOR_HOME_URL‘),
iconDir = URL + (URL.substr(URL.length - 1) == ‘/‘ ? ‘‘:‘/‘) + ‘dialogs/attachment/fileTypeImages/‘;
for (i = 0; i < filelist.length; i++) {
item = filelist[i];
icon = iconDir + getFileIcon(item.url);
title = item.title || item.url.substr(item.url.lastIndexOf(‘/‘) + 1);
html += ‘<p style="line-height: 16px;">‘ +
‘<img style="vertical-align: middle; margin-right: 2px;" src="‘+ icon + ‘" _src="‘ + icon + ‘" />‘ +
‘<a style="font-size:12px; color:#0066cc;" href="‘ + item.url +‘" title="‘ + title + ‘">‘ + title + ‘</a>‘ +
‘</p>‘;
}
me.execCommand(‘insertHtml‘, html);
}
}
}
}
});
修复过程
在 filelist = utils.isArray(filelist) ? filelist : [filelist]; 后面 ,或者在这个函数结束地方添加
添加一行代码
if(me.fireEvent(‘afterUpfile‘, filelist) === true){ return; }
标签:
原文地址:http://my.oschina.net/glenxu/blog/476720