Make time tooltips interactive (#23526)

Fixes https://codeberg.org/forgejo/forgejo/issues/511

<img width="379" alt="Screenshot 2023-03-16 at 20 23 10"
src="https://user-images.githubusercontent.com/115237/225731294-4c6e4f44-bdcc-4c8c-86e2-49f7c03b377d.png">
This commit is contained in:
silverwind 2023-03-16 21:40:56 +01:00 committed by GitHub
parent 4b72206805
commit 272cf6a2a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -233,7 +233,7 @@ func TimeSince(then time.Time, lang translation.Locale) template.HTML {
} }
func htmlTimeSince(then, now time.Time, lang translation.Locale) template.HTML { func htmlTimeSince(then, now time.Time, lang translation.Locale) template.HTML {
return template.HTML(fmt.Sprintf(`<span class="time-since tooltip" data-content="%s">%s</span>`, return template.HTML(fmt.Sprintf(`<span class="time-since tooltip" data-content="%s" data-tooltip-interactive="true">%s</span>`,
then.In(setting.DefaultUILocation).Format(GetTimeFormat(lang.Language())), then.In(setting.DefaultUILocation).Format(GetTimeFormat(lang.Language())),
timeSince(then, now, lang))) timeSince(then, now, lang)))
} }
@ -244,7 +244,7 @@ func TimeSinceUnix(then TimeStamp, lang translation.Locale) template.HTML {
} }
func htmlTimeSinceUnix(then, now TimeStamp, lang translation.Locale) template.HTML { func htmlTimeSinceUnix(then, now TimeStamp, lang translation.Locale) template.HTML {
return template.HTML(fmt.Sprintf(`<span class="time-since tooltip" data-content="%s">%s</span>`, return template.HTML(fmt.Sprintf(`<span class="time-since tooltip" data-content="%s" data-tooltip-interactive="true">%s</span>`,
then.FormatInLocation(GetTimeFormat(lang.Language()), setting.DefaultUILocation), then.FormatInLocation(GetTimeFormat(lang.Language()), setting.DefaultUILocation),
timeSinceUnix(int64(then), int64(now), lang))) timeSinceUnix(int64(then), int64(now), lang)))
} }

View File

@ -33,6 +33,7 @@ export function initTooltip(el, props = {}) {
content, content,
delay: 100, delay: 100,
role: 'tooltip', role: 'tooltip',
...(el.getAttribute('data-tooltip-interactive') === 'true' ? {interactive: true} : {}),
...props, ...props,
}); });
} }