Commit 6236715e authored by peterhegman's avatar peterhegman

Refactor how emoji title is added/removed

The general idea is to try and mimic how Bootstrap tooltips deal with
title attributes. If the status has a tooltip remove title attribute
from the emoji when the tooltip is open to prevent duplicate
tooltips. If the status does not have a tooltip leave it as is.
parent 68eb51e3
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
import { mapActions } from 'vuex'; import { mapActions } from 'vuex';
import timeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import timeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import GitlabTeamMemberBadge from '~/vue_shared/components/user_avatar/badges/gitlab_team_member_badge.vue'; import GitlabTeamMemberBadge from '~/vue_shared/components/user_avatar/badges/gitlab_team_member_badge.vue';
import $ from 'jquery';
export default { export default {
components: { components: {
...@@ -49,6 +48,8 @@ export default { ...@@ -49,6 +48,8 @@ export default {
data() { data() {
return { return {
isUsernameLinkHovered: false, isUsernameLinkHovered: false,
emojiTitle: '',
authorStatusHasTooltip: false,
}; };
}, },
computed: { computed: {
...@@ -87,28 +88,17 @@ export default { ...@@ -87,28 +88,17 @@ export default {
authorStatus() { authorStatus() {
return this.author.status_tooltip_html; return this.author.status_tooltip_html;
}, },
emojiElement() {
return this.$refs?.authorStatus?.querySelector('gl-emoji');
},
}, },
mounted() { mounted() {
// Temporarily remove `title` attribute from emoji when tooltip is open this.emojiTitle = this.emojiElement ? this.emojiElement.getAttribute('title') : '';
// Prevents duplicate tooltips (Bootstrap tooltip and browser title tooltip)
if (this.hasAuthorStatusWithTooltip()) {
const { authorStatus } = this.$refs;
const emoji = authorStatus.querySelector('gl-emoji');
const emojiTitle = emoji.getAttribute('title');
this.handleAuthorStatusTooltipShow = () => 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;
$(authorStatus).off('show.bs.tooltip', this.handleAuthorStatusTooltipShow); const authorStatusTitle = this.$refs?.authorStatus
$(authorStatus).off('hidden.bs.tooltip', this.handleAuthorStatusTooltipHidden); ?.querySelector('.user-status-emoji')
} ?.getAttribute('title');
this.authorStatusHasTooltip = authorStatusTitle && authorStatusTitle !== '';
}, },
methods: { methods: {
...mapActions(['setTargetNoteHash']), ...mapActions(['setTargetNoteHash']),
...@@ -120,19 +110,20 @@ export default { ...@@ -120,19 +110,20 @@ export default {
this.setTargetNoteHash(this.noteTimestampLink); this.setTargetNoteHash(this.noteTimestampLink);
} }
}, },
removeEmojiTitle() {
this.emojiElement.removeAttribute('title');
},
addEmojiTitle() {
this.emojiElement.setAttribute('title', this.emojiTitle);
},
handleUsernameMouseEnter() { handleUsernameMouseEnter() {
this.$refs.authorNameLink.dispatchEvent(new Event('mouseenter')); this.$refs.authorNameLink.dispatchEvent(new Event('mouseenter'));
this.isUsernameLinkHovered = true; this.isUsernameLinkHovered = true;
}, },
handleUsernameMouseLeave() { handleUsernameMouseLeave() {
this.$refs.authorNameLink.dispatchEvent(new Event('mouseleave')); this.$refs.authorNameLink.dispatchEvent(new Event('mouseleave'));
this.isUsernameLinkHovered = false; this.isUsernameLinkHovered = false;
}, },
hasAuthorStatusWithTooltip() {
return this.$refs.authorStatus?.querySelector('.user-status-emoji:not([title=""])');
},
}, },
}; };
</script> </script>
...@@ -160,7 +151,14 @@ export default { ...@@ -160,7 +151,14 @@ export default {
<slot name="note-header-info"></slot> <slot name="note-header-info"></slot>
<span class="note-header-author-name bold">{{ authorName }}</span> <span class="note-header-author-name bold">{{ authorName }}</span>
</a> </a>
<span v-if="authorStatus" ref="authorStatus" v-html="authorStatus"></span> <span
v-if="authorStatus"
ref="authorStatus"
v-on="
authorStatusHasTooltip ? { mouseenter: removeEmojiTitle, mouseleave: addEmojiTitle } : {}
"
v-html="authorStatus"
></span>
<span class="text-nowrap author-username"> <span class="text-nowrap author-username">
<a <a
ref="authorUsernameLink" ref="authorUsernameLink"
......
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