Skip to content

Commit 89c1ca3

Browse files
author
wangfupeng
committed
v2.1.6 修复若干bug,支持查看链接,支持自定义uploadImgName
1 parent 3d0c6b2 commit 89c1ca3

5 files changed

Lines changed: 206 additions & 21 deletions

File tree

dist/js/wangEditor.js

Lines changed: 173 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,15 +2203,23 @@ _e(function (E, $) {
22032203
var $txt = self.$txt;
22042204
var $p;
22052205

2206-
$txt.on('keyup', function (e) {
2206+
$txt.on('keydown', function (e) {
22072207
if (e.keyCode !== 8) {
22082208
return;
22092209
}
2210-
var txtHtml = $.trim($txt.html());
2210+
var txtHtml = $.trim($txt.html().toLowerCase());
22112211
if (txtHtml === '<p><br></p>') {
22122212
// 如果最后还剩余一个空行,就不再继续删除了
2213+
e.preventDefault();
22132214
return;
22142215
}
2216+
});
2217+
2218+
$txt.on('keyup', function (e) {
2219+
if (e.keyCode !== 8) {
2220+
return;
2221+
}
2222+
var txtHtml = $.trim($txt.html().toLowerCase());
22152223
// ff时用 txtHtml === '<br>' 判断,其他用 !txtHtml 判断
22162224
if (!txtHtml || txtHtml === '<br>') {
22172225
// 内容空了
@@ -2661,6 +2669,12 @@ _e(function (E, $) {
26612669
return;
26622670
}
26632671

2672+
// max-height 和『全屏』暂时有冲突
2673+
if (editor.menus.fullscreen) {
2674+
E.warn('max-height和『全屏』菜单一起使用时,会有一些问题尚未解决,请暂时不要两个同时使用');
2675+
return;
2676+
}
2677+
26642678
// 标记
26652679
editor.useMaxHeight = true;
26662680

@@ -3067,7 +3081,8 @@ _e(function (E, $) {
30673081
insertcode: '插入代码',
30683082
undo: '撤销',
30693083
redo: '重复',
3070-
fullscreen: '全屏'
3084+
fullscreen: '全屏',
3085+
openLink: '打开链接'
30713086
};
30723087

30733088
// 英文
@@ -3109,7 +3124,8 @@ _e(function (E, $) {
31093124
insertcode: 'Insert Code',
31103125
undo: 'Undo',
31113126
redo: 'Redo',
3112-
fullscreen: 'Full screnn'
3127+
fullscreen: 'Full screnn',
3128+
openLink: 'open link'
31133129
};
31143130
});
31153131
// 全局配置
@@ -3293,6 +3309,8 @@ _e(function (E, $) {
32933309
E.config.uploadTimeout = 20 * 1000;
32943310
// 用于存储上传回调事件
32953311
E.config.uploadImgFns = {};
3312+
// 自定义上传图片的filename
3313+
// E.config.uploadImgFileName = 'customFileName';
32963314

32973315
// 自定义上传,设置为 true 之后,显示上传图标
32983316
E.config.customUpload = false;
@@ -4489,6 +4507,10 @@ _e(function (E, $) {
44894507
return true;
44904508
}
44914509
}
4510+
if ($(elem).attr('align') === 'left') {
4511+
// ff 中,设置align-left之后,会是 <p align="left">xxx</p>
4512+
return true;
4513+
}
44924514
return false;
44934515
});
44944516
if (rangeElem) {
@@ -4532,6 +4554,10 @@ _e(function (E, $) {
45324554
return true;
45334555
}
45344556
}
4557+
if ($(elem).attr('align') === 'center') {
4558+
// ff 中,设置align-center之后,会是 <p align="center">xxx</p>
4559+
return true;
4560+
}
45354561
return false;
45364562
});
45374563
if (rangeElem) {
@@ -4575,6 +4601,10 @@ _e(function (E, $) {
45754601
return true;
45764602
}
45774603
}
4604+
if ($(elem).attr('align') === 'right') {
4605+
// ff 中,设置align-right之后,会是 <p align="right">xxx</p>
4606+
return true;
4607+
}
45784608
return false;
45794609
});
45804610
if (rangeElem) {
@@ -4913,16 +4943,16 @@ _e(function (E, $) {
49134943
// -------- 拼接tabel html --------
49144944

49154945
var i, j;
4916-
var tableHtml = '\n<table>';
4946+
var tableHtml = '<table>';
49174947
for (i = 0; i < rownum; i++) {
4918-
tableHtml += '\n <tr>';
4948+
tableHtml += '<tr>';
49194949

49204950
for (j = 0; j < colnum; j++) {
4921-
tableHtml += '\n <td><span>&nbsp;</span></td>';
4951+
tableHtml += '<td><span>&nbsp;</span></td>';
49224952
}
4923-
tableHtml += '\n </tr>';
4953+
tableHtml += '</tr>';
49244954
}
4925-
tableHtml += '\n</table>\n';
4955+
tableHtml += '</table>';
49264956

49274957
// -------- 执行命令 --------
49284958
editor.command(e, 'insertHtml', tableHtml);
@@ -6777,6 +6807,7 @@ _e(function (E, $) {
67776807
var filename = file.name || '';
67786808
var fileType = file.type || '';
67796809
var uploadImgFns = editor.config.uploadImgFns;
6810+
var uploadFileName = editor.config.uploadImgFileName || 'wangEditorH5File';
67806811
var onload = uploadImgFns.onload;
67816812
var ontimeout = uploadImgFns.ontimeout;
67826813
var onerror = uploadImgFns.onerror;
@@ -6805,7 +6836,7 @@ _e(function (E, $) {
68056836
filename: filename,
68066837
base64: base64,
68076838
fileType: fileType,
6808-
name: 'wangEditorH5File',
6839+
name: uploadFileName,
68096840
loadfn: function (resultText, xhr) {
68106841
clearInput();
68116842
// 执行配置中的方法
@@ -6875,6 +6906,7 @@ _e(function (E, $) {
68756906
UploadFile.fn.render = function () {
68766907
var self = this;
68776908
var editor = self.editor;
6909+
var uploadFileName = editor.config.uploadImgFileName || 'wangEditorFormFile';
68786910
if (self._hasRender) {
68796911
// 不要重复渲染
68806912
return;
@@ -6891,7 +6923,7 @@ _e(function (E, $) {
68916923
var multiple = self.multiple;
68926924
var multipleTpl = multiple ? 'multiple="multiple"' : '';
68936925
var $p = $('<p>选择图片并上传</p>');
6894-
var $input = $('<input type="file" ' + multipleTpl + ' name="wangEditorFormFile"/>');
6926+
var $input = $('<input type="file" ' + multipleTpl + ' name="' + uploadFileName + '"/>');
68956927
var $btn = $('<input type="submit" value="上传"/>');
68966928
var $form = $('<form enctype="multipart/form-data" method="post" action="' + uploadUrl + '" target="' + iframeId + '"></form>');
68976929
var $container = $('<div style="margin:10px 20px;"></div>');
@@ -7001,6 +7033,7 @@ _e(function (E, $) {
70017033
var $txt = txt.$txt;
70027034
var config = editor.config;
70037035
var uploadImgUrl = config.uploadImgUrl;
7036+
var uploadFileName = config.uploadImgFileName || 'wangEditorPasteFile';
70047037
var pasteEvent;
70057038
var $imgsBeforePaste;
70067039

@@ -7047,7 +7080,7 @@ _e(function (E, $) {
70477080
event: pasteEvent,
70487081
base64: base64,
70497082
fileType: type,
7050-
name: 'wangEditorPasteFile'
7083+
name: uploadFileName
70517084
});
70527085
} else {
70537086
E.log('src 为 ' + base64 + ' ,不是 base64 格式,暂时不支持上传');
@@ -7103,7 +7136,7 @@ _e(function (E, $) {
71037136
event: pasteEvent,
71047137
base64: base64,
71057138
fileType: fileType,
7106-
name: 'wangEditorPasteFile'
7139+
name: uploadFileName
71077140
});
71087141
};
71097142

@@ -7136,6 +7169,7 @@ _e(function (E, $) {
71367169
var $txt = txt.$txt;
71377170
var config = editor.config;
71387171
var uploadImgUrl = config.uploadImgUrl;
7172+
var uploadFileName = config.uploadImgFileName || 'wangEditorDragFile';
71397173

71407174
// 未配置上传图片url,则忽略
71417175
if (!uploadImgUrl) {
@@ -7179,7 +7213,7 @@ _e(function (E, $) {
71797213
event: dragEvent,
71807214
base64: base64,
71817215
fileType: type,
7182-
name: 'wangEditorDragFile'
7216+
name: uploadFileName
71837217
});
71847218
};
71857219

@@ -7900,6 +7934,131 @@ _e(function (E, $) {
79007934
});
79017935

79027936
});
7937+
// 编辑区域 link toolbar
7938+
_e(function (E, $) {
7939+
E.plugin(function () {
7940+
var editor = this;
7941+
var lang = editor.config.lang;
7942+
var $txt = editor.txt.$txt;
7943+
7944+
// 当前命中的链接
7945+
var $currentLink;
7946+
7947+
var $toolbar = $('<div class="txt-toolbar"></div>');
7948+
var $triangle = $('<div class="tip-triangle"></div>');
7949+
var $triggerLink = $('<a href="#" target="_blank"><i class="wangeditor-menu-img-link"></i> ' + lang.openLink + '</a>');
7950+
var isRendered;
7951+
7952+
// 记录当前的显示/隐藏状态
7953+
var isShow = false;
7954+
7955+
var showTimeoutId, hideTimeoutId;
7956+
var showTimeoutIdByToolbar, hideTimeoutIdByToolbar;
7957+
7958+
// 渲染 dom
7959+
function render() {
7960+
if (isRendered) {
7961+
return;
7962+
}
7963+
7964+
$toolbar.append($triangle)
7965+
.append($triggerLink);
7966+
7967+
editor.$editorContainer.append($toolbar);
7968+
7969+
isRendered = true;
7970+
}
7971+
7972+
// 定位
7973+
function setPosition() {
7974+
if (!$currentLink) {
7975+
return;
7976+
}
7977+
7978+
var position = $currentLink.position();
7979+
var left = position.left;
7980+
var top = position.top;
7981+
var height = $currentLink.height();
7982+
7983+
$toolbar.css({
7984+
top: top + height + 5,
7985+
left: left
7986+
});
7987+
}
7988+
7989+
// 显示 toolbar
7990+
function show() {
7991+
if (isShow) {
7992+
return;
7993+
}
7994+
7995+
if (!$currentLink) {
7996+
return;
7997+
}
7998+
7999+
render();
8000+
8001+
$toolbar.show();
8002+
8003+
// 设置链接
8004+
var href = $currentLink.attr('href');
8005+
$triggerLink.attr('href', href);
8006+
8007+
// 定位
8008+
setPosition();
8009+
8010+
isShow = true;
8011+
}
8012+
8013+
// 隐藏 toolbar
8014+
function hide() {
8015+
if (!isShow) {
8016+
return;
8017+
}
8018+
8019+
if (!$currentLink) {
8020+
return;
8021+
}
8022+
8023+
$toolbar.hide();
8024+
isShow = false;
8025+
}
8026+
8027+
// $txt 绑定事件
8028+
$txt.on('mouseenter', 'a', function (e) {
8029+
// 延时 500ms 显示toolbar
8030+
if (showTimeoutId) {
8031+
clearTimeout(showTimeoutId);
8032+
}
8033+
showTimeoutId = setTimeout(function () {
8034+
var a = e.currentTarget;
8035+
$currentLink = $(a);
8036+
show();
8037+
}, 500);
8038+
}).on('mouseleave', 'a', function (e) {
8039+
// 延时 500ms 隐藏toolbar
8040+
if (hideTimeoutId) {
8041+
clearTimeout(hideTimeoutId);
8042+
}
8043+
hideTimeoutId = setTimeout(hide, 500);
8044+
}).on('click keypress scroll', function (e) {
8045+
setTimeout(hide, 100);
8046+
});
8047+
// $toolbar 绑定事件
8048+
$toolbar.on('mouseenter', function (e) {
8049+
// 先中断掉 $txt.mouseleave 导致的隐藏
8050+
if (hideTimeoutId) {
8051+
clearTimeout(hideTimeoutId);
8052+
}
8053+
}).on('mouseleave', function (e) {
8054+
// 延时 500ms 显示toolbar
8055+
if (showTimeoutIdByToolbar) {
8056+
clearTimeout(showTimeoutIdByToolbar);
8057+
}
8058+
showTimeoutIdByToolbar = setTimeout(hide, 500);
8059+
});
8060+
});
8061+
});
79038062
// menu吸顶
79048063
_e(function (E, $) {
79058064

dist/js/wangEditor.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "wangeditor",
33
"filename": "dist/js/wangEditor.min.js",
4-
"version": "2.1.5",
4+
"version": "2.1.6",
55
"description": "wangEditor - 基于javascript和css开发的 Web富文本编辑器, 轻量、简洁、易用、开源免费",
66
"homepage": "http://wangeditor.github.io/",
77
"keywords": ["wangEditor", "富文本编辑器"],

test/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
// token1: 'abcde',
4444
// token2: '12345'
4545
};
46+
// editor.config.uploadImgFileName = 'myFileName';
4647

4748
// 表情显示项
4849
editor.config.emotionsShow = 'value';

test/z-test.html

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,34 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>test</title>
6+
<link rel="stylesheet" type="text/css" href="../dist/css/wangEditor.min.css">
7+
<style type="text/css">
8+
#editor-trigger {
9+
height: 400px;
10+
/*max-height: 500px;*/
11+
}
12+
.container {
13+
width: 100%;
14+
margin: 0 auto;
15+
position: relative;
16+
}
17+
</style>
618
</head>
719
<body>
8-
9-
20+
<p>wangEditor2.0 支持 IE8 浏览器</p>
21+
<div id="editor-container" class="container">
22+
<div id="editor-trigger">
23+
<p>请输入内容...</p>
24+
</div>
25+
</div>
26+
<p><br></p>
27+
28+
<script src="//cdn.bootcss.com/jquery/1.9.1/jquery.js"></script>
29+
<!--<script src="//cdn.bootcss.com/jquery/1.10.0/jquery.js"></script>-->
30+
<script type="text/javascript" src="../dist/js/wangEditor.js"></script>
31+
<script type="text/javascript">
32+
var editor = new wangEditor('editor-trigger');
33+
editor.create();
34+
</script>
1035
</body>
1136
</html>

0 commit comments

Comments
 (0)