mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 00:56:13 +01:00
fix: clicking outside postContainer should close tooltip
This commit is contained in:
@@ -464,11 +464,26 @@ define('forum/topic/postTools', [
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleSelectionTooltip() {
|
function handleSelectionTooltip() {
|
||||||
async function updateTooltip() {
|
hooks.onPage('action:posts.loaded', delayedTooltip);
|
||||||
|
|
||||||
|
$(document).off('mouseup', delayedTooltip).on('mouseup', delayedTooltip);
|
||||||
|
$(document).off('selectionchange', selectionChange).on('selectionchange', selectionChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
let selectionEmpty = true;
|
||||||
|
function selectionChange() {
|
||||||
|
selectionEmpty = window.getSelection().toString() === '';
|
||||||
|
if (selectionEmpty) {
|
||||||
|
$('[component="selection/tooltip"]').addClass('hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function delayedTooltip() {
|
||||||
|
setTimeout(async function () {
|
||||||
let selectionTooltip = $('[component="selection/tooltip"]');
|
let selectionTooltip = $('[component="selection/tooltip"]');
|
||||||
selectionTooltip.addClass('hidden');
|
selectionTooltip.addClass('hidden');
|
||||||
const selection = window.getSelection();
|
const selection = window.getSelection();
|
||||||
if (selection.focusNode && selection.type === 'Range' && ajaxify.data.template.topic) {
|
if (selection.focusNode && selection.type === 'Range' && ajaxify.data.template.topic && !selectionEmpty) {
|
||||||
const focusNode = $(selection.focusNode);
|
const focusNode = $(selection.focusNode);
|
||||||
const anchorNode = $(selection.anchorNode);
|
const anchorNode = $(selection.anchorNode);
|
||||||
const firstPid = anchorNode.parents('[data-pid]').attr('data-pid');
|
const firstPid = anchorNode.parents('[data-pid]').attr('data-pid');
|
||||||
@@ -495,6 +510,7 @@ define('forum/topic/postTools', [
|
|||||||
selectionTooltip.removeClass('hidden');
|
selectionTooltip.removeClass('hidden');
|
||||||
$(window).one('action:ajaxify.start', function () {
|
$(window).one('action:ajaxify.start', function () {
|
||||||
selectionTooltip.remove();
|
selectionTooltip.remove();
|
||||||
|
$(document).off('selectionchange', selectionChange);
|
||||||
});
|
});
|
||||||
const tooltipWidth = selectionTooltip.outerWidth(true);
|
const tooltipWidth = selectionTooltip.outerWidth(true);
|
||||||
selectionTooltip.css({
|
selectionTooltip.css({
|
||||||
@@ -502,17 +518,7 @@ define('forum/topic/postTools', [
|
|||||||
left: tooltipWidth > lastRect.width ? lastRect.left : lastRect.left + lastRect.width - tooltipWidth,
|
left: tooltipWidth > lastRect.width ? lastRect.left : lastRect.left + lastRect.width - tooltipWidth,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}, 0);
|
||||||
|
|
||||||
const postContainer = components.get('topic');
|
|
||||||
|
|
||||||
hooks.onPage('action:posts.loaded', function () {
|
|
||||||
setTimeout(updateTooltip, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
postContainer.on('mouseup', function () {
|
|
||||||
setTimeout(updateTooltip, 0);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return PostTools;
|
return PostTools;
|
||||||
|
|||||||
Reference in New Issue
Block a user