Skip to content

Commit 4e3d81e

Browse files
authored
Remove jQuery from the code diff expansion buttons (#29385)
- Removed all jQuery AJAX calls and replaced with htmx - Tested the code diff expansion buttons functionality and it works as before plus a loading indicator # Demo using `htmx` instead of jQuery AJAX ![action](https://github.com/go-gitea/gitea/assets/20454870/afba7442-ed56-4d39-b764-835d1f6c3a9c) Signed-off-by: Yarden Shoham <[email protected]>
1 parent 1f6de13 commit 4e3d81e

File tree

4 files changed

+12
-20
lines changed

4 files changed

+12
-20
lines changed

templates/repo/diff/blob_excerpt.tmpl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}">
66
<div class="gt-df">
77
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5)}}
8-
<button class="code-expander-button" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.PageIsWiki}}" data-anchor="{{$.Anchor}}">
8+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}">
99
{{svg "octicon-fold-down"}}
1010
</button>
1111
{{end}}
1212
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4)}}
13-
<button class="code-expander-button" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.PageIsWiki}}" data-anchor="{{$.Anchor}}">
13+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}">
1414
{{svg "octicon-fold-up"}}
1515
</button>
1616
{{end}}
1717
{{if eq $line.GetExpandDirection 2}}
18-
<button class="code-expander-button" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.PageIsWiki}}" data-anchor="{{$.Anchor}}">
18+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}">
1919
{{svg "octicon-fold"}}
2020
</button>
2121
{{end}}
@@ -51,17 +51,17 @@
5151
<td colspan="2" class="lines-num">
5252
<div class="gt-df">
5353
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5)}}
54-
<button class="code-expander-button" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}" data-anchor="{{$.Anchor}}">
54+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?data-query={{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}">
5555
{{svg "octicon-fold-down"}}
5656
</button>
5757
{{end}}
5858
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4)}}
59-
<button class="code-expander-button" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}" data-anchor="{{$.Anchor}}">
59+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?data-query={{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}">
6060
{{svg "octicon-fold-up"}}
6161
</button>
6262
{{end}}
6363
{{if eq $line.GetExpandDirection 2}}
64-
<button class="code-expander-button" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}" data-anchor="{{$.Anchor}}">
64+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?data-query={{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}">
6565
{{svg "octicon-fold"}}
6666
</button>
6767
{{end}}

templates/repo/diff/section_split.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
<td class="lines-num lines-num-old">
1919
<div class="gt-df">
2020
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5)}}
21-
<button class="code-expander-button" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}" data-anchor="diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
21+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
2222
{{svg "octicon-fold-down"}}
2323
</button>
2424
{{end}}
2525
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4)}}
26-
<button class="code-expander-button" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}" data-anchor="diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
26+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
2727
{{svg "octicon-fold-up"}}
2828
</button>
2929
{{end}}
3030
{{if eq $line.GetExpandDirection 2}}
31-
<button class="code-expander-button" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}" data-anchor="diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
31+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
3232
{{svg "octicon-fold"}}
3333
</button>
3434
{{end}}

templates/repo/diff/section_unified.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
<td colspan="2" class="lines-num">
1515
<div class="gt-df">
1616
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5)}}
17-
<button class="code-expander-button" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}" data-anchor="diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
17+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
1818
{{svg "octicon-fold-down"}}
1919
</button>
2020
{{end}}
2121
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4)}}
22-
<button class="code-expander-button" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}" data-anchor="diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
22+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
2323
{{svg "octicon-fold-up"}}
2424
</button>
2525
{{end}}
2626
{{if eq $line.GetExpandDirection 2}}
27-
<button class="code-expander-button" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}" data-anchor="diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
27+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
2828
{{svg "octicon-fold"}}
2929
</button>
3030
{{end}}

web_src/js/features/repo-code.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,6 @@ export function initRepoCodeView() {
186186
$(document).on('click', '.fold-file', ({currentTarget}) => {
187187
invertFileFolding(currentTarget.closest('.file-content'), currentTarget);
188188
});
189-
$(document).on('click', '.code-expander-button', async ({currentTarget}) => {
190-
const url = currentTarget.getAttribute('data-url');
191-
const query = currentTarget.getAttribute('data-query');
192-
const anchor = currentTarget.getAttribute('data-anchor');
193-
if (!url) return;
194-
const blob = await $.get(`${url}?${query}&anchor=${anchor}`);
195-
currentTarget.closest('tr').outerHTML = blob;
196-
});
197189
$(document).on('click', '.copy-line-permalink', async ({currentTarget}) => {
198190
await clippie(toAbsoluteUrl(currentTarget.getAttribute('data-url')));
199191
});

0 commit comments

Comments
 (0)