diff options
author | silverwind <me@silverwind.io> | 2022-08-12 23:03:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-12 17:03:41 -0400 |
commit | 20b3a904504d401cfc192b80440d76d787af94d9 (patch) | |
tree | 76e086bb19c9e6614aa4b872c7ec1f8073da19e3 /modules | |
parent | 74515d3d17c578ee0083111951188cb159fd049b (diff) | |
download | gitea-20b3a904504d401cfc192b80440d76d787af94d9.tar.gz gitea-20b3a904504d401cfc192b80440d76d787af94d9.zip |
Remove useless JS operation for relative time tooltips (#20756)
This operation that shifts the content from title to data-content is
useless when we can directly render the expected HTML instead.
This change does prevent these tooltips from working when the user has
JS disabled in their browser, but I think we made it clear by now that
JS is required for gitea to work properly.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/timeutil/since.go | 4 | ||||
-rw-r--r-- | modules/timeutil/since_test.go | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/modules/timeutil/since.go b/modules/timeutil/since.go index 5e89b0faa2..8473d45051 100644 --- a/modules/timeutil/since.go +++ b/modules/timeutil/since.go @@ -234,7 +234,7 @@ func TimeSince(then 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" title="%s">%s</span>`, + return template.HTML(fmt.Sprintf(`<span class="time-since tooltip" data-content="%s">%s</span>`, then.In(setting.DefaultUILocation).Format(GetTimeFormat(lang.Language())), timeSince(then, now, lang))) } @@ -245,7 +245,7 @@ func TimeSinceUnix(then 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" title="%s">%s</span>`, + return template.HTML(fmt.Sprintf(`<span class="time-since tooltip" data-content="%s">%s</span>`, then.FormatInLocation(GetTimeFormat(lang.Language()), setting.DefaultUILocation), timeSinceUnix(int64(then), int64(now), lang))) } diff --git a/modules/timeutil/since_test.go b/modules/timeutil/since_test.go index 8bdb9d7546..dfcf9cb01d 100644 --- a/modules/timeutil/since_test.go +++ b/modules/timeutil/since_test.go @@ -119,7 +119,7 @@ func TestHtmlTimeSince(t *testing.T) { // test that `diff` yields a result containing `expected` test := func(expected string, diff time.Duration) { actual := htmlTimeSince(BaseDate, BaseDate.Add(diff), translation.NewLocale("en-US")) - assert.Contains(t, actual, `title="Sat Jan 1 00:00:00 UTC 2000"`) + assert.Contains(t, actual, `data-content="Sat Jan 1 00:00:00 UTC 2000"`) assert.Contains(t, actual, expected) } test("1 second", time.Second) |