Improve comment bubble

pull/1/head
yflory 4 years ago
parent a685f4601f
commit af695510bb

@ -177,13 +177,19 @@ body.cp-app-pad {
} }
div.cp-comment-bubble { div.cp-comment-bubble {
position: relative; position: relative;
order: 2;
button { button {
.fa { .fa {
margin: 0 !important; margin: 0 !important;
} }
left: 10px;
position: absolute; position: absolute;
padding: 0 4px;
background: @cp_toolbar-bg;
margin-left: 0px;
margin-top: 20px;
line-height: unset;
&:hover {
background: @toolbar-bg-active;
}
} }
} }
#cp-app-pad-comments { #cp-app-pad-comments {
@ -204,8 +210,7 @@ body.cp-app-pad {
&.cke_body_width { &.cke_body_width {
div.cp-comment-bubble { div.cp-comment-bubble {
button { button {
right: -10px; margin-left: 30px;
left: unset;
} }
} }
iframe { iframe {

@ -749,31 +749,19 @@ define([
}; };
var updateBubble = function(Env) { var updateBubble = function(Env) {
if (!Env.bubble) { return; } if (!Env.bubble) { return; }
var pos = Env.bubble.node.getBoundingClientRect(); var pos = Env.bubble.range.getClientRects()[0];
if (pos.y < 0 || pos.y > Env.$inner.outerHeight()) { var left = pos.x + pos.width;
//removeCommentBubble(Env); Env.bubble.button.setAttribute('style', 'top:' + pos.y + 'px; left: '+left+'px');
}
Env.bubble.button.setAttribute('style', 'top:' + pos.y + 'px');
}; };
var addCommentBubble = function(Env) { var addCommentBubble = function(Env) {
var ranges = Env.editor.getSelectedRanges(); var ranges = Env.editor.getSelectedRanges();
if (!ranges.length) { return; } if (!ranges.length) { return; }
var el = ranges[0].endContainer || ranges[0].startContainer;
var node = el && el.$;
if (!node) { return; }
if (node.nodeType === Node.TEXT_NODE) {
node = node.parentNode;
if (!node) { return; }
}
var pos = node.getBoundingClientRect();
var y = pos.y;
if (y < 0 || y > Env.$inner.outerHeight()) { return; }
var button = h('button.btn.btn-secondary', { var button = h('button.btn.btn-secondary', {
style: 'top:' + y + 'px;',
title: Messages.comments_comment title: Messages.comments_comment
}, h('i.fa.fa-commenting')); }, h('i.fa.fa-commenting'));
Env.bubble = { Env.bubble = {
node: node, range: ranges[0],
button: button button: button
}; };
$(button).click(function(e)  { $(button).click(function(e)  {
@ -781,7 +769,8 @@ define([
Env.editor.execCommand('comment'); Env.editor.execCommand('comment');
Env.bubble = undefined; Env.bubble = undefined;
}); });
Env.$contentContainer.append(h('div.cp-comment-bubble', button)); Env.$contentContainer.find('iframe').before(h('div.cp-comment-bubble', button));
updateBubble(Env);
}; };
var isEditable = function (document) { var isEditable = function (document) {

Loading…
Cancel
Save