Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使插入多张图片和插入单张图片的逻辑保持一致。 #19

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions _src/adapter/imagescale.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ UM.registerUI('imagescale',function () {
});

me.addListener('click', function (type, e) {
if (e.target.tagName == 'IMG' && me.body.contentEditable!="false") {
// 使用unselectable属性(IE私有)标识是否可选
if (e.target.tagName == 'IMG' && me.body.contentEditable!="false" && e.target.getAttribute('unselectable') !== 'on') {
var range = new dom.Range(me.document, me.body);
range.selectNode(e.target).select();
}
});

}
});
});
34 changes: 18 additions & 16 deletions _src/plugins/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
*/
UM.commands['insertimage'] = {
execCommand:function (cmd, opt) {
function image(ci) {
var style = ci['floatStyle'] == 'left' || ci['floatStyle'] == 'right' ? 'float:' + ci['floatStyle'] + ';' : '';

return '<img src="' + ci.src + '" ' + (ci._src ? ' _src="' + ci._src + '" ' : '') +
(ci.unselectable ? ' unselectable="on" class="edui-unselectable"' : '') + // IE 10-
(ci.width ? ' width="' + ci.width + '" ' : '') +
(ci.height ? ' height="' + ci.height + '" ' : '') +
' style="' + style + '"'+
(ci.title && ci.title != "" ? ' title="' + ci.title + '"' : '') +
(ci.border && ci.border != "0" ? ' border="' + ci.border + '"' : '') +
(ci.alt && ci.alt != "" ? ' alt="' + ci.alt + '"' : '') +
(ci.hspace && ci.hspace != "0" ? ' hspace = "' + ci.hspace + '"' : '') +
(ci.vspace && ci.vspace != "0" ? ' vspace = "' + ci.vspace + '"' : '') + '/>';
}

opt = utils.isArray(opt) ? opt : [opt];
if (!opt.length) {
return;
Expand All @@ -19,32 +34,19 @@ UM.commands['insertimage'] = {
var html = [], str = '', ci;
ci = opt[0];
if (opt.length == 1) {
str = '<img src="' + ci.src + '" ' + (ci._src ? ' _src="' + ci._src + '" ' : '') +
(ci.width ? 'width="' + ci.width + '" ' : '') +
(ci.height ? ' height="' + ci.height + '" ' : '') +
(ci['floatStyle'] == 'left' || ci['floatStyle'] == 'right' ? ' style="float:' + ci['floatStyle'] + ';"' : '') +
(ci.title && ci.title != "" ? ' title="' + ci.title + '"' : '') +
(ci.border && ci.border != "0" ? ' border="' + ci.border + '"' : '') +
(ci.alt && ci.alt != "" ? ' alt="' + ci.alt + '"' : '') +
(ci.hspace && ci.hspace != "0" ? ' hspace = "' + ci.hspace + '"' : '') +
(ci.vspace && ci.vspace != "0" ? ' vspace = "' + ci.vspace + '"' : '') + '/>';
str = image(ci);
if (ci['floatStyle'] == 'center') {
str = '<p style="text-align: center">' + str + '</p>';
}
html.push(str);

} else {
for (var i = 0; ci = opt[i++];) {
str = '<p ' + (ci['floatStyle'] == 'center' ? 'style="text-align: center" ' : '') + '><img src="' + ci.src + '" ' +
(ci.width ? 'width="' + ci.width + '" ' : '') + (ci._src ? ' _src="' + ci._src + '" ' : '') +
(ci.height ? ' height="' + ci.height + '" ' : '') +
' style="' + (ci['floatStyle'] && ci['floatStyle'] != 'center' ? 'float:' + ci['floatStyle'] + ';' : '') +
(ci.border || '') + '" ' +
(ci.title ? ' title="' + ci.title + '"' : '') + ' /></p>';
str = '<p ' + (ci['floatStyle'] == 'center' ? 'style="text-align: center" ' : '') + '>' + image(ci) + '</p>';
html.push(str);
}
}

me.execCommand('insertHtml', html.join(''), true);
}
};
};
9 changes: 8 additions & 1 deletion themes/default/_css/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@
}
.edui-editor-body.focus{border:1px solid #5c9dff}
.edui-editor-body table{margin:10px 0 10px;border-collapse:collapse;display:table;}
.edui-editor-body td{padding: 5px 10px;border: 1px solid #DDD;}
.edui-editor-body td{padding: 5px 10px;border: 1px solid #DDD;}
.edui-unselectable{
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
-khtml-user-select: none;
user-select: none;
}