Commit 68eb51e3 authored by peterhegman's avatar peterhegman

Remove tooltip event listeners in `beforeDestroy`

parent 1e5f1eb8
...@@ -91,18 +91,23 @@ export default { ...@@ -91,18 +91,23 @@ export default {
mounted() { mounted() {
// Temporarily remove `title` attribute from emoji when tooltip is open // Temporarily remove `title` attribute from emoji when tooltip is open
// Prevents duplicate tooltips (Bootstrap tooltip and browser title tooltip) // Prevents duplicate tooltips (Bootstrap tooltip and browser title tooltip)
const { authorStatus } = this.$refs; if (this.hasAuthorStatusWithTooltip()) {
if (authorStatus && authorStatus.querySelector('.has-tooltip')) { const { authorStatus } = this.$refs;
const emoji = authorStatus.querySelector('gl-emoji'); const emoji = authorStatus.querySelector('gl-emoji');
const emojiTitle = emoji.getAttribute('title'); const emojiTitle = emoji.getAttribute('title');
$(this.$refs.authorStatus).on('show.bs.tooltip', () => { this.handleAuthorStatusTooltipShow = () => emoji.removeAttribute('title');
emoji.removeAttribute('title'); this.handleAuthorStatusTooltipHidden = () => emoji.setAttribute('title', emojiTitle);
}); $(authorStatus).on('show.bs.tooltip', this.handleAuthorStatusTooltipShow);
$(authorStatus).on('hidden.bs.tooltip', this.handleAuthorStatusTooltipHidden);
}
},
beforeDestroy() {
if (this.hasAuthorStatusWithTooltip()) {
const { authorStatus } = this.$refs;
$(this.$refs.authorStatus).on('hidden.bs.tooltip', () => { $(authorStatus).off('show.bs.tooltip', this.handleAuthorStatusTooltipShow);
emoji.setAttribute('title', emojiTitle); $(authorStatus).off('hidden.bs.tooltip', this.handleAuthorStatusTooltipHidden);
});
} }
}, },
methods: { methods: {
...@@ -125,6 +130,9 @@ export default { ...@@ -125,6 +130,9 @@ export default {
this.isUsernameLinkHovered = false; this.isUsernameLinkHovered = false;
}, },
hasAuthorStatusWithTooltip() {
return this.$refs.authorStatus?.querySelector('.user-status-emoji:not([title=""])');
},
}, },
}; };
</script> </script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment