Skip to content

Commit 666a019

Browse files
committed
fix
1 parent e91843a commit 666a019

File tree

4 files changed

+37
-65
lines changed

4 files changed

+37
-65
lines changed
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
<div class="branch-and-tag-area">
2-
<button class="ui button ellipsis-button gt-mt-3 load-tags-and-branches" data-fetch-url="{{.RepoLink}}/commit/{{.CommitID}}/load-branches-and-tags" data-tooltip-content="{{.locale.Tr "repo.commit.load_referencing_branches_and_tags"}}" data-contained-in-text="{{.locale.Tr "repo.commit.contained_in"}}" aria-expanded="false">...</button>
3-
<div class="ui divider branch-tag-area-divider gt-hidden"></div>
4-
<div class="branch-tag-area-text gt-df"></div>
5-
<div class="branch-area-parent gt-df gt-ac gt-my-3 gt-gap-2 gt-hidden">
6-
{{svg "octicon-git-branch" 16 "gt-min-w-16"}}
7-
<div class="branch-area gt-df gt-ac gt-fw gt-hidden" data-defaultbranch-tooltip="{{.locale.Tr "repo.commit.contained_in_default_branch"}}"></div>
8-
</div>
9-
<div class="tag-area-parent gt-df gt-ac gt-my-3 gt-gap-2 gt-hidden">
10-
{{svg "octicon-tag" 16 "gt-min-w-16"}}
11-
<div class="tag-area gt-df gt-ac gt-fw gt-hidden"></div>
1+
<div class="branch-and-tag-area" data-text-default-branch-tooltip="{{.locale.Tr "repo.commit.contained_in_default_branch"}}">
2+
<button class="ui button ellipsis-button load-branches-and-tags gt-mt-3" aria-expanded="false"
3+
data-fetch-url="{{.RepoLink}}/commit/{{.CommitID}}/load-branches-and-tags"
4+
data-tooltip-content="{{.locale.Tr "repo.commit.load_referencing_branches_and_tags"}}"
5+
>...</button>
6+
<div class="branch-and-tag-detail gt-hidden">
7+
<div class="divider"></div>
8+
<div>{{.locale.Tr "repo.commit.contained_in"}}</div>
9+
<div class="branch-area flex-text-block gt-mt-3">{{svg "octicon-git-branch"}}</div>
10+
<div class="tag-area flex-text-block gt-mt-3">{{svg "octicon-tag"}}</div>
1211
</div>
1312
</div>

web_src/css/helpers.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ Gitea's private styles use `g-` prefix.
8282
.gt-w-screen { width: 100vw !important; }
8383
.gt-h-screen { height: 100vh !important; }
8484

85-
.gt-min-w-0 { min-width: 0 !important; }
86-
.gt-min-w-16 { min-width: 16px !important; } /*There are some weird bugs with flexboxes and SVGs where the svgs shrink into oblivion*/
87-
8885
.gt-float-left { float: left !important; }
8986
.gt-float-right { float: right !important; }
9087
.gt-clear-both { clear: both !important; }
Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,52 @@
1-
import {showElem} from '../utils/dom.js';
1+
import {showElem, toggleElem} from '../utils/dom.js';
22

3-
async function loadBranchesAndTags(loadingButton, addHere) {
3+
async function loadBranchesAndTags(area, loadingButton) {
44
loadingButton.classList.add('disabled');
5-
let res;
65
try {
7-
res = await fetch(loadingButton.getAttribute('data-fetch-url'), {
8-
method: 'GET',
9-
});
6+
const res = await fetch(loadingButton.getAttribute('data-fetch-url'));
7+
const data = await res.json();
8+
loadingButton.classList.add('gt-hidden');
9+
addTags(area, data.tags);
10+
addBranches(area, data.branches, data.default_branch);
11+
showElem(area.querySelectorAll('.branch-and-tag-detail'));
1012
} finally {
1113
loadingButton.classList.remove('disabled');
1214
}
13-
14-
if (!res.ok) {
15-
return;
16-
}
17-
18-
const data = await res.json();
19-
showAreas('.branch-tag-area-divider');
20-
loadingButton.classList.add('gt-hidden');
21-
addHere.querySelector('.branch-tag-area-text').textContent = loadingButton.getAttribute('data-contained-in-text');
22-
addTags(data.tags, addHere.querySelector('.tag-area'));
23-
const branchArea = addHere.querySelector('.branch-area');
24-
addBranches(
25-
data.branches,
26-
data.default_branch,
27-
branchArea.getAttribute('data-defaultbranch-tooltip'),
28-
branchArea,
29-
);
3015
}
3116

32-
function addTags(tags, addHere) {
33-
if (tags.length > 0) showAreas('.tag-area,.tag-area-parent');
17+
function addTags(area, tags) {
18+
toggleElem(area.querySelectorAll('.tag-area-parent'), tags.length > 0);
19+
const tagArea = area.querySelector('.tag-area');
3420
for (const tag of tags) {
35-
addLink(tag.web_link, tag.name, addHere);
21+
addLink(tagArea, tag.web_link, tag.name);
3622
}
3723
}
3824

39-
function addBranches(branches, defaultBranch, defaultBranchTooltip, addHere) {
40-
if (branches.length > 0) showAreas('.branch-area,.branch-area-parent');
25+
function addBranches(area, branches, defaultBranch) {
26+
const defaultBranchTooltip = area.getAttribute('data-text-default-branch-tooltip');
27+
toggleElem(area.querySelectorAll('.branch-area-parent'), branches.length > 0);
28+
const branchArea = area.querySelector('.branch-area');
4129
for (const branch of branches) {
42-
addLink(
43-
branch.web_link,
44-
branch.name,
45-
addHere,
46-
defaultBranch === branch.name ? defaultBranchTooltip : undefined,
47-
);
30+
const tooltip = defaultBranch === branch.name ? defaultBranchTooltip : null;
31+
addLink(branchArea, branch.web_link, branch.name, tooltip);
4832
}
4933
}
5034

51-
function showAreas(selector) {
52-
for (const branchArea of document.querySelectorAll(selector)) showElem(branchArea);
53-
}
54-
55-
function addLink(href, text, addHere, tooltip) {
35+
function addLink(parent, href, text, tooltip) {
5636
const link = document.createElement('a');
57-
link.classList.add('muted', 'gt-px-3', 'gt-rounded');
37+
link.classList.add('muted', 'gt-px-2', 'gt-rounded');
38+
link.href = href;
39+
link.textContent = text;
5840
if (tooltip) {
5941
link.classList.add('gt-border-secondary');
6042
link.setAttribute('data-tooltip-content', tooltip);
6143
}
62-
link.href = href;
63-
link.textContent = text;
64-
addHere.append(link);
44+
parent.append(link);
6545
}
6646

6747
export function initLoadBranchesAndTagsButton() {
68-
for (const loadButton of document.querySelectorAll('.load-tags-and-branches')) {
69-
loadButton.addEventListener('click', () => {
70-
loadBranchesAndTags(
71-
loadButton,
72-
document.querySelector('.branch-and-tag-area'),
73-
);
74-
});
48+
for (const area of document.querySelectorAll('.branch-and-tag-area')) {
49+
const loadButton = area.querySelector('.load-branches-and-tags');
50+
loadButton.addEventListener('click', () => loadBranchesAndTags(area, loadButton));
7551
}
7652
}

web_src/js/features/repo-legacy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ async function onEditContent(event) {
459459
}
460460

461461
export function initRepository() {
462-
if ($('.repository').length === 0) {
462+
if ($('.page-content.repository').length === 0) {
463463
return;
464464
}
465465

0 commit comments

Comments
 (0)