Skip to content

Commit 20b3a90

Browse files
silverwindlunnytechknowlogick
authored
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 <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 74515d3 commit 20b3a90

File tree

4 files changed

+4
-12
lines changed

4 files changed

+4
-12
lines changed

Diff for: integrations/repo_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func testViewRepo(t *testing.T) {
6464
}
6565
})
6666

67-
f.commitTime, _ = s.Find("span.time-since").Attr("title")
67+
f.commitTime, _ = s.Find("span.time-since").Attr("data-content")
6868
items = append(items, f)
6969
})
7070

Diff for: modules/timeutil/since.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func TimeSince(then time.Time, lang translation.Locale) template.HTML {
234234
}
235235

236236
func htmlTimeSince(then, now time.Time, lang translation.Locale) template.HTML {
237-
return template.HTML(fmt.Sprintf(`<span class="time-since" title="%s">%s</span>`,
237+
return template.HTML(fmt.Sprintf(`<span class="time-since tooltip" data-content="%s">%s</span>`,
238238
then.In(setting.DefaultUILocation).Format(GetTimeFormat(lang.Language())),
239239
timeSince(then, now, lang)))
240240
}
@@ -245,7 +245,7 @@ func TimeSinceUnix(then TimeStamp, lang translation.Locale) template.HTML {
245245
}
246246

247247
func htmlTimeSinceUnix(then, now TimeStamp, lang translation.Locale) template.HTML {
248-
return template.HTML(fmt.Sprintf(`<span class="time-since" title="%s">%s</span>`,
248+
return template.HTML(fmt.Sprintf(`<span class="time-since tooltip" data-content="%s">%s</span>`,
249249
then.FormatInLocation(GetTimeFormat(lang.Language()), setting.DefaultUILocation),
250250
timeSinceUnix(int64(then), int64(now), lang)))
251251
}

Diff for: modules/timeutil/since_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func TestHtmlTimeSince(t *testing.T) {
119119
// test that `diff` yields a result containing `expected`
120120
test := func(expected string, diff time.Duration) {
121121
actual := htmlTimeSince(BaseDate, BaseDate.Add(diff), translation.NewLocale("en-US"))
122-
assert.Contains(t, actual, `title="Sat Jan 1 00:00:00 UTC 2000"`)
122+
assert.Contains(t, actual, `data-content="Sat Jan 1 00:00:00 UTC 2000"`)
123123
assert.Contains(t, actual, expected)
124124
}
125125
test("1 second", time.Second)

Diff for: web_src/js/features/common-global.js

-8
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ export function initGlobalTooltips() {
7070
}
7171

7272
export function initGlobalCommon() {
73-
// Show exact time
74-
$('.time-since').each(function () {
75-
$(this)
76-
.addClass('tooltip')
77-
.attr('data-content', $(this).attr('title'))
78-
.attr('title', '');
79-
});
80-
8173
// Undo Safari emoji glitch fix at high enough zoom levels
8274
if (navigator.userAgent.match('Safari')) {
8375
$(window).resize(() => {

0 commit comments

Comments
 (0)