Fix race condition between click events in comments

pull/1/head
yflory 5 years ago
parent 003ad074a5
commit b37b8c4b31

@ -99,6 +99,8 @@
} }
} }
.cp-comment-edit { .cp-comment-edit {
cursor: pointer;
outline: none;
position: absolute; position: absolute;
right: 0; right: 0;
top: 0; top: 0;

@ -266,7 +266,7 @@ define([
]); ]);
$(deleteButton).click(function (e) { $(deleteButton).click(function (e) {
e.stopPropagation(); e.stopPropagation();
cb(); cb(false);
}); });
} }
@ -406,9 +406,12 @@ define([
var edit; var edit;
if (i === (obj.m.length -1) && author.curvePublic === userData.curvePublic) { if (i === (obj.m.length -1) && author.curvePublic === userData.curvePublic) {
edit = h('span.cp-comment-edit', { edit = h('span.cp-comment-edit', {
tabindex:1,
title: Messages.clickToEdit title: Messages.clickToEdit
}, h('i.fa.fa-pencil')); }, h('i.fa.fa-pencil'));
$(edit).click(function (e) { $(edit).click(function (e) {
Env.$container.find('.cp-comment-active').removeClass('cp-comment-active');
$div.addClass('cp-comment-active');
e.stopPropagation(); e.stopPropagation();
Env.$container.find('.cp-comment-form').remove(); Env.$container.find('.cp-comment-form').remove();
if ($actions) { $actions.hide(); } if ($actions) { $actions.hide(); }
@ -418,12 +421,14 @@ define([
.find('.cp-comment-actions').css('display', ''); .find('.cp-comment-actions').css('display', '');
$(form).remove(); $(form).remove();
if (typeof(val) === "undefined") { return; }
var obj = Env.comments.data[key]; var obj = Env.comments.data[key];
if (!obj || !Array.isArray(obj.m)) { return; } if (!obj || !Array.isArray(obj.m)) { return; }
var msg = obj.m[i]; var msg = obj.m[i];
if (!msg) { return; } if (!msg) { return; }
// i is our index // i is our index
if (!val) { if (val === false) {
msg.d = 1; msg.d = 1;
if (container) { if (container) {
$(container).addClass('cp-comment-deleted') $(container).addClass('cp-comment-deleted')
@ -563,7 +568,7 @@ define([
if (!visible) { $last[0].scrollIntoView(); } if (!visible) { $last[0].scrollIntoView(); }
}; };
$div.on('click focus', function () { $div.on('click focus', function (e) {
if ($div.hasClass('cp-comment-active')) { return; } if ($div.hasClass('cp-comment-active')) { return; }
Env.$container.find('.cp-comment-active').removeClass('cp-comment-active'); Env.$container.find('.cp-comment-active').removeClass('cp-comment-active');
$div.addClass('cp-comment-active'); $div.addClass('cp-comment-active');
@ -832,12 +837,14 @@ define([
} }
Env.$container.find('.cp-comment-active').removeClass('cp-comment-active'); Env.$container.find('.cp-comment-active').removeClass('cp-comment-active');
Env.$inner.find('comment.active').removeClass('active'); Env.$inner.find('comment.active').removeClass('active');
Env.$container.find('.cp-comment-form').remove();
}); });
// Unselect comment when clicking on another part of the doc // Unselect comment when clicking on another part of the doc
Env.$inner.on('click', function (e) { Env.$inner.on('click', function (e) {
if ($(e.target).closest('comment').length) { return; } if ($(e.target).closest('comment').length) { return; }
Env.$container.find('.cp-comment-active').removeClass('cp-comment-active'); Env.$container.find('.cp-comment-active').removeClass('cp-comment-active');
Env.$inner.find('comment.active').removeClass('active'); Env.$inner.find('comment.active').removeClass('active');
Env.$container.find('.cp-comment-form').remove();
}); });
Env.$inner.on('click', 'comment', function (e) { Env.$inner.on('click', 'comment', function (e) {
var $comment = $(e.target); var $comment = $(e.target);

Loading…
Cancel
Save