Skip to content

Commit 9be90a5

Browse files
authored
Use a general approach to show tooltip, fix temporary tooltip bug (#23574)
## TLDR * Improve performance: lazy creating the tippy instances. * Transparently support all "tooltip" elements, no need to call `initTooltip` again and again. * Fix a temporary tooltip re-entrance bug, which causes showing temp content forever. * Upgrade vue3-calendar-heatmap to 2.0.2 with lazy tippy init (initHeatmap time decreases from 100ms to 50ms) ## Details ### The performance Creating a lot of tippy tooltip instances is expensive. This PR doesn't create all tippy tooltip instances, instead, it only adds "mouseover" event listener to necessary elements, and then switches to the tippy tooltip ### The general approach for all tooltips Before, dynamically generated tooltips need to be called with `initTooltip`. After, use MutationObserver to: * Attach the event listeners to newly created tooltip elements, work for Vue (easier than before) * Catch changed attributes and update the tooltip content (better than before) It does help a lot, eg: https://github.com/go-gitea/gitea/blob/1a4efa0ee9a49d48549be7479a46be133b9bc260/web_src/js/components/PullRequestMergeForm.vue#L33-L36 ### Temporary tooltip re-entrance bug To reproduce, on try.gitea.io, click the "copy clone url" quickly, then the tooltip will be "Copied!" forever. After this PR, with the help of `attachTippyTooltip`, the tooltip content could be reset to the default correctly. ### Other changes * `data-tooltip-content` is preferred from now on, the old `data-content` may cause conflicts with other modules. * `data-placement` was only used for tooltip, so it's renamed to `data-tooltip-placement`, and removed from `createTippy`.
1 parent e7f0bcf commit 9be90a5

File tree

13 files changed

+111
-64
lines changed

13 files changed

+111
-64
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"vue": "3.2.47",
4444
"vue-bar-graph": "2.0.0",
4545
"vue-loader": "17.0.1",
46-
"vue3-calendar-heatmap": "2.0.0",
46+
"vue3-calendar-heatmap": "2.0.2",
4747
"webpack": "5.76.2",
4848
"webpack-cli": "5.0.1",
4949
"workbox-routing": "6.5.4",

templates/repo/issue/view_content/sidebar.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,9 @@
661661
{{if and (not (eq .Issue.PullRequest.HeadRepo.FullName .Issue.PullRequest.BaseRepo.FullName)) .CanWriteToHeadRepo}}
662662
<div class="ui divider"></div>
663663
<div class="inline field">
664-
<div class="ui checkbox" id="allow-edits-from-maintainers"
664+
<div class="ui checkbox tooltip" id="allow-edits-from-maintainers"
665665
data-url="{{.Issue.Link}}"
666-
data-prompt-tip="{{.locale.Tr "repo.pulls.allow_edits_from_maintainers_desc"}}"
666+
data-tooltip-content="{{.locale.Tr "repo.pulls.allow_edits_from_maintainers_desc"}}"
667667
data-prompt-error="{{.locale.Tr "repo.pulls.allow_edits_from_maintainers_err"}}"
668668
>
669669
<label><strong>{{.locale.Tr "repo.pulls.allow_edits_from_maintainers"}}</strong></label>

templates/repo/sub_menu.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</div>
4141
<a class="ui segment language-stats">
4242
{{range .LanguageStats}}
43-
<div class="bar tooltip" style="width: {{.Percentage}}%; background-color: {{.Color}}" data-placement="top" data-content={{.Language}}>&nbsp;</div>
43+
<div class="bar tooltip" style="width: {{.Percentage}}%; background-color: {{.Color}}" data-tooltip-placement="top" data-tooltip-content={{.Language}}>&nbsp;</div>
4444
{{end}}
4545
</a>
4646
{{end}}

web_src/js/components/DashboardRepoList.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@
147147
<script>
148148
import {createApp, nextTick} from 'vue';
149149
import $ from 'jquery';
150-
import {initTooltip} from '../modules/tippy.js';
151150
import {SvgIcon} from '../svg.js';
152151
153152
const {appSubUrl, assetUrlPrefix, pageData} = window.config;
@@ -238,9 +237,6 @@ const sfc = {
238237
mounted() {
239238
const el = document.getElementById('dashboard-repo-list');
240239
this.changeReposFilter(this.reposFilter);
241-
for (const elTooltip of el.querySelectorAll('.tooltip')) {
242-
initTooltip(elTooltip);
243-
}
244240
$(el).find('.dropdown').dropdown();
245241
nextTick(() => {
246242
this.$refs.search.focus();

web_src/js/components/DiffFileList.vue

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
</template>
2222

2323
<script>
24-
import {initTooltip} from '../modules/tippy.js';
2524
import {doLoadMoreFiles} from '../features/repo-diff.js';
2625
2726
const {pageData} = window.config;
@@ -30,17 +29,6 @@ export default {
3029
data: () => {
3130
return pageData.diffFileInfo;
3231
},
33-
watch: {
34-
fileListIsVisible(newValue) {
35-
if (newValue === true) {
36-
this.$nextTick(() => {
37-
for (const el of this.$refs.root.querySelectorAll('.tooltip')) {
38-
initTooltip(el);
39-
}
40-
});
41-
}
42-
}
43-
},
4432
mounted() {
4533
document.getElementById('show-file-list-btn').addEventListener('click', this.toggleFileList);
4634
},

web_src/js/components/DiffFileTreeItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div v-show="show" class="tooltip" :title="item.name">
2+
<div v-show="show" :title="item.name">
33
<!--title instead of tooltip above as the tooltip needs too much work with the current methods, i.e. not being loaded or staying open for "too long"-->
44
<div class="item" :class="item.isFile ? 'filewrapper gt-p-1' : ''">
55
<!-- Files -->

web_src/js/features/common-global.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {createDropzone} from './dropzone.js';
55
import {initCompColorPicker} from './comp/ColorPicker.js';
66
import {showGlobalErrorMessage} from '../bootstrap.js';
77
import {handleGlobalEnterQuickSubmit} from './comp/QuickSubmit.js';
8-
import {initTooltip} from '../modules/tippy.js';
98
import {svg} from '../svg.js';
109
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
1110

@@ -66,12 +65,6 @@ export function initGlobalButtonClickOnEnter() {
6665
});
6766
}
6867

69-
export function initGlobalTooltips() {
70-
for (const el of document.getElementsByClassName('tooltip')) {
71-
initTooltip(el);
72-
}
73-
}
74-
7568
export function initGlobalCommon() {
7669
// Undo Safari emoji glitch fix at high enough zoom levels
7770
if (navigator.userAgent.match('Safari')) {

web_src/js/features/contextpopup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function initContextPopups() {
3030

3131
createTippy(this, {
3232
content: el,
33+
placement: 'top-start',
3334
interactive: true,
3435
interactiveBorder: 5,
3536
onShow: () => {

web_src/js/features/repo-diff.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {initCompReactionSelector} from './comp/ReactionSelector.js';
33
import {initRepoIssueContentHistory} from './repo-issue-content.js';
44
import {validateTextareaNonEmpty} from './comp/EasyMDE.js';
55
import {initViewedCheckboxListenerFor, countAndUpdateViewedFiles} from './pull-view-file.js';
6-
import {initTooltip} from '../modules/tippy.js';
76

87
const {csrfToken} = window.config;
98

@@ -60,10 +59,6 @@ export function initRepoDiffConversationForm() {
6059
const $newConversationHolder = $(await $.post($form.attr('action'), formDataString));
6160
const {path, side, idx} = $newConversationHolder.data();
6261

63-
$newConversationHolder.find('.tooltip').each(function () {
64-
initTooltip(this);
65-
});
66-
6762
$form.closest('.conversation-holder').replaceWith($newConversationHolder);
6863
if ($form.closest('tr').data('line-type') === 'same') {
6964
$(`[data-path="${path}"] a.add-code-comment[data-idx="${idx}"]`).addClass('invisible');

0 commit comments

Comments
 (0)