提交 ae8b7bb5 编写于 作者: J Jinqn

优化错误提示方式,上传错误使用冒泡提示错误信息

上级 f2d29223
......@@ -19,7 +19,7 @@
<body>
<div>
<h1>完整demo</h1>
<script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>
<script id="editor" type="text/plain" style="width:100%;height:500px;"></script>
</div>
<div id="btns">
<div>
......@@ -52,9 +52,9 @@
</div>
<div>
<button onclick="createEditor()"/>
<button onclick="createEditor()">
创建编辑器</button>
<button onclick="deleteEditor()"/>
<button onclick="deleteEditor()">
删除编辑器</button>
</div>
......
......@@ -114,8 +114,10 @@
'ui/multiMenu.js',
'ui/shortcutmenu.js',
'ui/breakline.js',
'ui/message.js',
'adapter/editorui.js',
'adapter/editor.js'
'adapter/editor.js',
'adapter/message.js'
],
baseURL = '../_src/';
for (var i=0,pi;pi = paths[i++];) {
......
......@@ -401,8 +401,10 @@
'<div id="##_toolbarmsg_label" class="%%-toolbarmsg-label"></div>' +
'<div style="height:0;overflow:hidden;clear:both;"></div>' +
'</div>' +
'<div id="##_message_holder" class="%%-messageholder"></div>' +
'</div>' +
'<div id="##_iframeholder" class="%%-iframeholder">' +
'</div>' +
'<div id="##_iframeholder" class="%%-iframeholder"></div>' +
//modify wdcount by matao
'<div id="##_bottombar" class="%%-bottomContainer"><table><tr>' +
'<td id="##_elementpath" class="%%-bottombar"></td>' +
......
UE.registerUI('message', function(editor) {
var uiUtils = baidu.editor.ui.uiUtils;
var editorui = baidu.editor.ui;
var Message = editorui.Message;
var holder;
var _messageItems = [];
var me = editor;
me.addListener('ready', function(){
holder = document.getElementById(me.ui.id + '_message_holder');
updateHolderPos();
});
me.addListener('showmessage', function(type, opt){
var message = new Message({
'timeout': opt.timeout,
'type': opt.info,
'title': opt.title,
'keepshow': opt.keepshow,
'editor': me
}),
mid = opt.id || ('msg_' + (+new Date()).toString(36));
message.render(holder);
_messageItems[mid] = message;
message.reset(opt);
setTimeout(function(){
updateHolderPos();
}, 300);
return mid;
});
me.addListener('updatemessage',function(type, id, opt){
var message = _messageItems[id];
message && message.reset(opt);
});
me.addListener('hidemessage',function(type, id, opt){
var message = _messageItems[id];
message && message.hide();
});
function updateHolderPos(){
var toolbarbox = me.ui.getDom('toolbarbox');
if (toolbarbox) {
holder.style.top = toolbarbox.offsetHeight + 3 + 'px';
}
holder.style.zIndex = Math.max(me.options.zIndex, me.iframe.style.zIndex) + 1;
}
});
......@@ -22,17 +22,21 @@
me.fireEvent('serverConfigLoaded');
me._serverConfigLoaded = true;
} catch (e) {
console && console.error('后台配置项返回出错!');
showErrorMsg(me.getLang('loadconfigFormatError'));
}
},
'onerror':function(){
console && console.error('获取后台配置项出错!');
showErrorMsg(me.getLang('loadconfigHttpError'));
}
});
} catch(e){
console && console.log('获取后台配置项请求出错!');
showErrorMsg(me.getLang('loadconfigError'));
}
});
function showErrorMsg(msg) {
console && console.error(msg);
}
};
UE.Editor.prototype.isServerConfigLoaded = function(){
......
......@@ -6,36 +6,40 @@
* @date 2013-10-14
*/
UE.plugin.register('autoupload', function (){
var me = this;
function sendAndInsertFile(file, editor) {
var me = editor;
//模拟数据
var fieldName, urlPrefix, maxSize, allowFiles, actionUrl,
loadingHtml, errorHandler, successHandler,
filetype = /image\/\w+/i.test(file.type) ? 'image':'file',
loadingId = 'loading_' + (+new Date()).toString(36);
fieldName = editor.getOpt(filetype + 'FieldName');
urlPrefix = editor.getOpt(filetype + 'UrlPrefix');
maxSize = editor.getOpt(filetype + 'MaxSize');
allowFiles = editor.getOpt(filetype + 'AllowFiles');
actionUrl = editor.getActionUrl(editor.getOpt(filetype + 'ActionName'));
fieldName = me.getOpt(filetype + 'FieldName');
urlPrefix = me.getOpt(filetype + 'UrlPrefix');
maxSize = me.getOpt(filetype + 'MaxSize');
allowFiles = me.getOpt(filetype + 'AllowFiles');
actionUrl = me.getActionUrl(me.getOpt(filetype + 'ActionName'));
errorHandler = function(title) {
var loader = editor.document.getElementById(loadingId);
var loader = me.document.getElementById(loadingId);
if (loader) {
domUtils.removeClasses(loader, 'loadingclass');
domUtils.addClass(loader, 'loaderrorclass');
loader.setAttribute('title', title || '');
domUtils.remove(loader);
me.fireEvent('showmessage', {
'id': loadingId,
'title': title,
'type': 'error',
'timeout': 4000
});
}
};
if (filetype == 'image') {
loadingHtml = '<img class="loadingclass" id="' + loadingId + '" src="' +
editor.options.themePath + editor.options.theme +
'/images/spacer.gif" title="' + (editor.getLang('autoupload.loading') || '') + '" >';
me.options.themePath + me.options.theme +
'/images/spacer.gif" title="' + (me.getLang('autoupload.loading') || '') + '" >';
successHandler = function(data) {
var link = urlPrefix + data.url,
loader = editor.document.getElementById(loadingId);
loader = me.document.getElementById(loadingId);
if (loader) {
loader.setAttribute('src', link);
loader.setAttribute('_src', link);
......@@ -48,33 +52,33 @@ UE.plugin.register('autoupload', function (){
} else {
loadingHtml = '<p>' +
'<img class="loadingclass" id="' + loadingId + '" src="' +
editor.options.themePath + editor.options.theme +
'/images/spacer.gif" title="' + (editor.getLang('autoupload.loading') || '') + '" >' +
me.options.themePath + me.options.theme +
'/images/spacer.gif" title="' + (me.getLang('autoupload.loading') || '') + '" >' +
'</p>';
successHandler = function(data) {
var link = urlPrefix + data.url,
loader = editor.document.getElementById(loadingId);
loader = me.document.getElementById(loadingId);
var rng = editor.selection.getRange(),
var rng = me.selection.getRange(),
bk = rng.createBookmark();
rng.selectNode(loader).select();
editor.execCommand('insertfile', {'url': link});
me.execCommand('insertfile', {'url': link});
rng.moveToBookmark(bk).select();
};
}
/* 插入loading的占位符 */
editor.execCommand('inserthtml', loadingHtml);
me.execCommand('inserthtml', loadingHtml);
/* 判断文件大小是否超出限制 */
if(file.size > maxSize) {
errorHandler(editor.getLang('autoupload.exceedSizeError'));
errorHandler(me.getLang('autoupload.exceedSizeError'));
return;
}
/* 判断文件格式是否超出允许 */
var fileext = file.name ? file.name.substr(file.name.lastIndexOf('.')):'';
if ((fileext && filetype != 'image') || (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)) {
errorHandler(editor.getLang('autoupload.exceedTypeError'));
errorHandler(me.getLang('autoupload.exceedTypeError'));
return;
}
......@@ -97,7 +101,7 @@ UE.plugin.register('autoupload', function (){
errorHandler(json.state);
}
}catch(er){
errorHandler(editor.getLang('autoupload.loadError'));
errorHandler(me.getLang('autoupload.loadError'));
}
});
xhr.send(fd);
......@@ -126,6 +130,7 @@ UE.plugin.register('autoupload', function (){
bindEvents:{
//插入粘贴板的图片,拖放插入图片
'ready':function(e){
var me = this;
if(window.FormData && window.FileReader) {
domUtils.on(me.body, 'paste drop', function(e){
var hasImg = false,
......
......@@ -68,9 +68,13 @@ UE.plugin.register('simpleupload', function (){
function showErrorLoader(title){
if(loadingId) {
var loader = me.document.getElementById(loadingId);
domUtils.removeClasses(loader, 'loadingclass');
domUtils.addClass(loader, 'loaderrorclass');
loader.setAttribute('title', title || '');
loader && domUtils.remove(loader);
me.fireEvent('showmessage', {
'id': loadingId,
'title': title,
'type': 'error',
'timeout': 4000
});
}
}
......
///import core
///import uicore
(function () {
var utils = baidu.editor.utils,
uiUtils = baidu.editor.ui.uiUtils,
domUtils = baidu.editor.dom.domUtils,
UIBase = baidu.editor.ui.UIBase,
Message = baidu.editor.ui.Message = function (options){
this.initOptions(options);
this.initMessage();
};
Message.prototype = {
initMessage: function (){
this.initUIBase();
},
getHtmlTpl: function (){
return '<div id="##" class="edui-message %%">' +
' <div id="##_closer" class="edui-message-closer">×</div>' +
' <div id="##_body" class="edui-message-body edui-message-type-info">' +
' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
' <div class="edui-shadow"></div>' +
' <div id="##_title" class="edui-message-title">' +
' </div>' +
' </div>' +
'</div>';
},
reset: function(opt){
var me = this;
if (!opt.keepshow) {
clearTimeout(this.timer);
me.timer = setTimeout(function(){
me.hide();
}, opt.timeout || 4000);
}
opt.title !== undefined && me.setTitle(opt.title);
opt.type !== undefined && me.setType(opt.type);
me.show();
},
postRender: function(){
var me = this,
closer = this.getDom('closer');
closer && domUtils.on(closer, 'click', function(){
me.hide();
});
},
setTitle: function(title){
this.getDom('title').innerHTML = title;
},
setType: function(type){
type = type || 'info';
var body = this.getDom('body');
body.className = body.className.replace(/edui-message-type-[\w-]+/, 'edui-message-type-' + type);
},
getTitle: function(){
return this.getDom('title').innerHTML;
},
getType: function(){
var arr = this.getDom('body').match(/edui-message-type-([\w-]+)/);
return arr ? arr[1]:'';
},
show: function (){
this.getDom().style.display = 'block';
},
hide: function (){
this.getDom().style.display = 'none';
}
};
utils.inherits(Message, UIBase);
})();
......@@ -5,12 +5,13 @@
1. 修复hasContents接口在非ie下只有空格时判断还为真的问题
2. 修复在粘贴word内容时,会误命中cm,pt这样的文本内容变成px的问题
3. 优化删除编辑器再创建编辑器时,编辑器的容器id发生变化的问题
4. 提交的xss漏洞
4. 修复提交jsonp请求时,callback参数的xss漏洞
5. 新增jsp后台多种服务器配置下的路径定位
6. 修复ZeroClipboard的flash地址参数名称错误
7. 修复getActionUrl的bug
8. 整理代码中的参数到ueditor.config.js里
8. 整理配置参数,把遗漏在代码中的配置项整理到ueditor.config.js里
9. 修复图片拉伸工具和编辑拉伸长高器的样式冲突
10. 优化错误提示方式,上传错误使用冒泡提示错误信息
##1.4.2
###重构前后端交互功能
......
......@@ -90,6 +90,9 @@ UE.I18N['en'] = {
'closeDialog':"closeDialog",
'tableDrag':"You must import the file uiUtils.js before drag! ",
'autofloatMsg':"The plugin AutoFloat depends on EditorUI!",
'loadconfigError': 'Get server config error.',
'loadconfigFormatError': 'Server config format error.',
'loadconfigHttpError': 'Get server config http error.',
'snapScreen_plugin':{
'browserMsg':"Only IE supported!",
'callBackErrorMsg':"The callback data is wrong,please check the config!",
......
......@@ -69,6 +69,7 @@ UE.I18N['zh-cn'] = {
},
'autoupload': {
'exceedSizeError': '文件大小超出限制',
'exceedTypeError': '文件格式不允许',
'jsonEncodeError': '服务器返回格式错误',
'loading':"正在上传...",
'loadError':"上传错误"
......@@ -89,6 +90,9 @@ UE.I18N['zh-cn'] = {
'closeDialog':"关闭对话框",
'tableDrag':"表格拖动必须引入uiUtils.js文件!",
'autofloatMsg':"工具栏浮动依赖编辑器UI,您首先需要引入UI文件!",
'loadconfigError': '获取后台配置项请求出错!',
'loadconfigFormatError': '后台配置项返回格式出错!',
'loadconfigHttpError': '请求后台配置项http错误!',
'snapScreen_plugin':{
'browserMsg':"仅支持IE浏览器!",
'callBackErrorMsg':"服务器返回数据有误,请检查配置项之后重试。",
......
......@@ -9,7 +9,7 @@ $action = $_GET['action'];
switch ($action) {
case 'config':
$result = json_encode($CONFIG);
//$result = json_encode($CONFIG);
break;
/* 上传图片 */
......
.edui-default .edui-editor-messageholder {
display: block;
width: 150px;
height: auto;
border: 0;
margin: 0;
padding: 0;
position: absolute;
top: 28px;
right: 3px;
}
.edui-default .edui-message{
min-height: 10px;
text-shadow: 0 1px 0 rgba(255,255,255,0.5);
padding: 0;
margin-bottom: 3px;
}
.edui-default .edui-message-body{
border-radius: 3px;
padding: 8px;
color: #c09853;
background-color: #fcf8e3;
border: 1px solid #fbeed5;
}
.edui-default .edui-message-type-info{
color: #3a87ad;
background-color: #d9edf7;
border-color: #bce8f1
}
.edui-default .edui-message-type-success{
color: #468847;
background-color: #dff0d8;
border-color: #d6e9c6
}
.edui-default .edui-message-type-danger,
.edui-default .edui-message-type-error{
color: #b94a48;
background-color: #f2dede;
border-color: #eed3d7
}
.edui-default .edui-message .edui-message-closer {
display: block;
width: 16px;
height: 16px;
line-height: 16px;
position: relative;
top: 0;
right: 0;
padding: 0;
cursor: pointer;
background: transparent;
border: 0;
float: right;
font-size: 20px;
font-weight: bold;
color: #999;
text-shadow: 0 1px 0 #fff;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
}
.edui-default .edui-message .edui-message-title {
font-size: 10pt;
word-wrap: break-word;
word-break: normal;
}
\ No newline at end of file
......@@ -28,6 +28,8 @@
@import "splitbutton.css";
/*弹出菜单*/
@import "popup.css";
/*提示消息*/
@import "message.css";
/*-------独立按钮样式,按需加载-------*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册