diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-03-23 17:56:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-23 17:56:15 +0800 |
commit | 9be90a58754061171bbd5025d85d2b891364efd3 (patch) | |
tree | 71326587b80bf21bd0d46fca192aa430e7ee2ac8 /templates | |
parent | e7f0bcf8847330d646300b60d9fda119da7e97dc (diff) | |
download | gitea-9be90a58754061171bbd5025d85d2b891364efd3.tar.gz gitea-9be90a58754061171bbd5025d85d2b891364efd3.zip |
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`.
Diffstat (limited to 'templates')
-rw-r--r-- | templates/repo/issue/view_content/sidebar.tmpl | 4 | ||||
-rw-r--r-- | templates/repo/sub_menu.tmpl | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index cef1e3a02e..fb7c77f4eb 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -661,9 +661,9 @@ {{if and (not (eq .Issue.PullRequest.HeadRepo.FullName .Issue.PullRequest.BaseRepo.FullName)) .CanWriteToHeadRepo}} <div class="ui divider"></div> <div class="inline field"> - <div class="ui checkbox" id="allow-edits-from-maintainers" + <div class="ui checkbox tooltip" id="allow-edits-from-maintainers" data-url="{{.Issue.Link}}" - data-prompt-tip="{{.locale.Tr "repo.pulls.allow_edits_from_maintainers_desc"}}" + data-tooltip-content="{{.locale.Tr "repo.pulls.allow_edits_from_maintainers_desc"}}" data-prompt-error="{{.locale.Tr "repo.pulls.allow_edits_from_maintainers_err"}}" > <label><strong>{{.locale.Tr "repo.pulls.allow_edits_from_maintainers"}}</strong></label> diff --git a/templates/repo/sub_menu.tmpl b/templates/repo/sub_menu.tmpl index 5c1688d019..adb1e3079f 100644 --- a/templates/repo/sub_menu.tmpl +++ b/templates/repo/sub_menu.tmpl @@ -40,7 +40,7 @@ </div> <a class="ui segment language-stats"> {{range .LanguageStats}} - <div class="bar tooltip" style="width: {{.Percentage}}%; background-color: {{.Color}}" data-placement="top" data-content={{.Language}}> </div> + <div class="bar tooltip" style="width: {{.Percentage}}%; background-color: {{.Color}}" data-tooltip-placement="top" data-tooltip-content={{.Language}}> </div> {{end}} </a> {{end}} |