Skip to content

Commit 12fff36

Browse files
authored
Fine tune more downdrop settings, use SVG for labels, improve Repo Topic Edit form (#23626)
Although it seems that some different purposes are mixed in this PR, however, they are all related, and can be tested together, so I put them together to save everyone's time. Diff: `+79 −84`, everything becomes much better. ### Improve the dropdown settings. Move all fomantic-init related code into our `fomantic.js` Fine-tune some dropdown global settings, see the comments. Also help to fix the first problem in #23625 , cc: @yp05327 The "language" menu has been simplified, and it works with small-height window better. ### Use SVG instead of `<i class="delete icon">` It's also done by `$.fn.dropdown.settings.templates.label` , cc: @silverwind ### Remove incorrect `tabable` CSS class It doesn't have CSS styles, and it was only in Vue. So it's totally unnecessary, remove it by the way. ### Improve the Repo Topic Edit form * Simplify the code * Add a "Cancel" button * Align elements Before: <details> ![image](https://user-images.githubusercontent.com/2114189/223325782-f09532de-0c38-4742-ba86-ed35cc9a858d.png) </details> After: ![image](https://user-images.githubusercontent.com/2114189/226796347-207feb0a-b3cd-4820-8a3e-01930bab1069.png)
1 parent ac64c82 commit 12fff36

File tree

10 files changed

+80
-86
lines changed

10 files changed

+80
-86
lines changed

templates/base/footer_content.tmpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
{{if .ShowFooterBranding}}
2020
<a target="_blank" rel="noopener noreferrer" href="https://github.com/go-gitea/gitea">{{svg "octicon-mark-github"}}<span class="sr-only">GitHub</span></a>
2121
{{end}}
22-
<div class="ui language bottom floating slide up dropdown link item">
23-
{{svg "octicon-globe"}}
24-
<span>{{.locale.LangName}}</span>
22+
<div class="ui dropdown upward language">
23+
<span>{{svg "octicon-globe"}} {{.locale.LangName}}</span>
2524
<div class="menu language-menu">
2625
{{range .AllLangs}}
2726
<a lang="{{.Lang}}" data-url="{{AppSubUrl}}/?lang={{.Lang}}" class="item {{if eq $.locale.Lang .Lang}}active selected{{end}}">{{.Name}}</a>

templates/repo/home.tmpl

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,29 @@
2828
</div>
2929
{{end}}
3030
</div>
31-
<div class="gt-mt-3" id="repo-topics">
32-
{{range .Topics}}<a class="ui repo-topic large label topic" href="{{AppSubUrl}}/explore/repos?q={{.Name}}&topic=1">{{.Name}}</a>{{end}}
33-
{{if and .Permission.IsAdmin (not .Repository.IsArchived)}}<a id="manage_topic" class="muted">{{.locale.Tr "repo.topic.manage_topics"}}</a>{{end}}
31+
<div class="gt-df gt-ac gt-fw gt-mt-3" id="repo-topics">
32+
{{range .Topics}}<a class="ui repo-topic large label topic" href="{{AppSubUrl}}/explore/repos?q={{.Name}}&topic=1">{{.Name}}</a>{{end}}
33+
{{if and .Permission.IsAdmin (not .Repository.IsArchived)}}<button id="manage_topic" class="ui button tiny tertiary gt-ml-2">{{.locale.Tr "repo.topic.manage_topics"}}</button>{{end}}
3434
</div>
3535
{{end}}
3636
{{if and .Permission.IsAdmin (not .Repository.IsArchived)}}
37-
<div class="ui repo-topic-edit grid form gt-hidden" id="topic_edit">
38-
<div class="fourteen wide column">
39-
<div class="field">
40-
<div class="ui fluid multiple search selection dropdown">
41-
<input type="hidden" name="topics" value="{{range $i, $v := .Topics}}{{.Name}}{{if lt (Add $i 1) (len $.Topics)}},{{end}}{{end}}">
42-
{{range .Topics}}
43-
<div class="ui small label topic transition visible" data-value="{{.Name}}" style="display: inline-block !important; cursor: default;">{{.Name}}{{svg "octicon-x" 16 "delete icon gt-ml-3 gt-mt-1"}}</div>
44-
{{end}}
45-
<div class="text"></div>
46-
</div>
37+
<div class="ui form gt-hidden gt-df gt-mt-4" id="topic_edit">
38+
<div class="field gt-f1 gt-mr-3">
39+
<div class="ui fluid multiple search selection dropdown" data-text-count-prompt="{{.locale.Tr "repo.topic.count_prompt"}}" data-text-format-prompt="{{.locale.Tr "repo.topic.format_prompt"}}">
40+
<input type="hidden" name="topics" value="{{range $i, $v := .Topics}}{{.Name}}{{if lt (Add $i 1) (len $.Topics)}},{{end}}{{end}}">
41+
{{range .Topics}}
42+
{{/* keey the same layout as Fomantic UI generated labels */}}
43+
<a class="ui label transition visible gt-cursor-default" data-value="{{.Name}}" style="display: inline-block !important;">{{.Name}}{{svg "octicon-x" 16 "delete icon"}}</a>
44+
{{end}}
45+
<div class="text"></div>
4746
</div>
4847
</div>
49-
<div class="two wide column">
50-
<a class="ui button primary" role="button" tabindex="0" id="save_topic"
51-
data-link="{{.RepoLink}}/topics">{{.locale.Tr "repo.topic.done"}}</a>
48+
<div>
49+
<button class="ui basic button secondary" id="cancel_topic_edit">{{.locale.Tr "cancel"}}</button>
50+
<button class="ui primary button" id="save_topic" data-link="{{.RepoLink}}/topics">{{.locale.Tr "save"}}</button>
5251
</div>
5352
</div>
5453
{{end}}
55-
<div class="gt-hidden" id="validate_prompt">
56-
<span id="count_prompt">{{.locale.Tr "repo.topic.count_prompt"}}</span>
57-
<span id="format_prompt">{{.locale.Tr "repo.topic.format_prompt"}}</span>
58-
</div>
5954
{{if .Repository.IsArchived}}
6055
<div class="ui warning message">
6156
{{.locale.Tr "repo.archive.title"}}

web_src/css/base.css

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,15 +1854,15 @@ footer .container .links > *:first-child {
18541854
}
18551855

18561856
footer .ui.language .menu {
1857-
max-height: 500px;
1857+
height: 500px;
1858+
max-height: calc(100vh - 60px);
18581859
overflow-y: auto;
18591860
margin-bottom: 7px;
18601861
}
18611862

18621863
footer .ui.language .svg {
18631864
margin-right: 0.15em;
1864-
vertical-align: top;
1865-
margin-top: calc(2em - 16px);
1865+
margin-top: 1px;
18661866
}
18671867

18681868
footer .ui.left,
@@ -2387,6 +2387,10 @@ a.ui.label:hover {
23872387
color: var(--color-text);
23882388
}
23892389

2390+
.ui.tertiary.button:focus {
2391+
color: var(--color-text-dark);
2392+
}
2393+
23902394
.ui.primary.label,
23912395
.ui.primary.labels .label {
23922396
background-color: var(--color-primary) !important;

web_src/css/helpers.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
.gt-pointer-events-none { pointer-events: none !important; }
2424
.gt-relative { position: relative !important; }
2525
.gt-overflow-x-scroll { overflow-x: scroll !important; }
26+
.gt-cursor-default { cursor: default !important; }
2627

2728
.gt-mono {
2829
font-family: var(--fonts-monospace) !important;

web_src/css/repository.css

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,21 +3062,10 @@ tbody.commit-list {
30623062
top: -2px;
30633063
}
30643064

3065-
#topic_edit {
3066-
margin-top: 5px;
3067-
}
3068-
3069-
#repo-topics {
3070-
margin-top: 5px;
3071-
display: flex;
3072-
align-items: center;
3073-
flex-wrap: wrap;
3074-
}
3075-
3076-
.repo-topic {
3077-
font-weight: normal !important;
3065+
#repo-topics .repo-topic {
3066+
font-weight: normal;
30783067
cursor: pointer;
3079-
margin: 2px !important;
3068+
margin: 2px;
30803069
}
30813070

30823071
#new-dependency-drop-list.ui.selection.dropdown {
@@ -3092,18 +3081,6 @@ tbody.commit-list {
30923081
overflow: hidden;
30933082
}
30943083

3095-
#manage_topic {
3096-
font-size: 12px;
3097-
}
3098-
3099-
.label + #manage_topic {
3100-
margin-left: 5px;
3101-
}
3102-
3103-
.ui.small.label.topic {
3104-
margin-bottom: 4px;
3105-
}
3106-
31073084
.repo-header {
31083085
display: flex;
31093086
align-items: center;

web_src/js/components/DashboardRepoList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<div v-if="!isOrganization" class="ui two item tabable menu">
3+
<div v-if="!isOrganization" class="ui two item menu">
44
<a :class="{item: true, active: tab === 'repos'}" @click="changeTab('repos')">{{ textRepository }}</a>
55
<a :class="{item: true, active: tab === 'organizations'}" @click="changeTab('organizations')">{{ textOrganization }}</a>
66
</div>

web_src/js/features/common-global.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function initGlobalCommon() {
8383
const $uiDropdowns = $('.ui.dropdown');
8484

8585
// do not init "custom" dropdowns, "custom" dropdowns are managed by their own code.
86-
$uiDropdowns.filter(':not(.custom)').dropdown({fullTextSearch: 'exact'});
86+
$uiDropdowns.filter(':not(.custom)').dropdown();
8787

8888
// The "jump" means this dropdown is mainly used for "menu" purpose,
8989
// clicking an item will jump to somewhere else or trigger an action/function.
@@ -111,14 +111,12 @@ export function initGlobalCommon() {
111111
},
112112
});
113113

114-
// special animations/popup-directions
115-
$uiDropdowns.filter('.slide.up').dropdown({transition: 'slide up'});
116-
$uiDropdowns.filter('.upward').dropdown({direction: 'upward'});
114+
// special popup-directions
115+
$uiDropdowns.filter('.upward').dropdown('setting', 'direction', 'upward');
117116

118117
$('.ui.checkbox').checkbox();
119118

120119
$('.tabular.menu .item').tab();
121-
$('.tabable.menu .item').tab();
122120

123121
$('.toggle.button').on('click', function () {
124122
toggleElem($($(this).data('target')));

web_src/js/features/repo-home.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,29 @@ const {appSubUrl, csrfToken} = window.config;
66

77
export function initRepoTopicBar() {
88
const mgrBtn = $('#manage_topic');
9+
if (!mgrBtn.length) return;
910
const editDiv = $('#topic_edit');
1011
const viewDiv = $('#repo-topics');
1112
const saveBtn = $('#save_topic');
1213
const topicDropdown = $('#topic_edit .dropdown');
13-
const topicForm = $('#topic_edit.ui.form');
14-
const topicPrompts = getPrompts();
14+
const topicForm = editDiv; // the old logic, editDiv is topicForm
15+
const topicDropdownSearch = topicDropdown.find('input.search');
16+
const topicPrompts = {
17+
countPrompt: topicDropdown.attr('data-text-count-prompt'),
18+
formatPrompt: topicDropdown.attr('data-text-format-prompt'),
19+
};
1520

1621
mgrBtn.on('click', () => {
1722
hideElem(viewDiv);
1823
showElem(editDiv);
24+
topicDropdownSearch.focus();
1925
});
2026

21-
function getPrompts() {
22-
const hidePrompt = $('#validate_prompt');
23-
const prompts = {
24-
countPrompt: hidePrompt.children('#count_prompt').text(),
25-
formatPrompt: hidePrompt.children('#format_prompt').text()
26-
};
27-
hidePrompt.remove();
28-
return prompts;
29-
}
27+
$('#cancel_topic_edit').on('click', () => {
28+
hideElem(editDiv);
29+
showElem(viewDiv);
30+
mgrBtn.focus();
31+
});
3032

3133
saveBtn.on('click', () => {
3234
const topics = $('input[name=topics]').val();
@@ -39,13 +41,11 @@ export function initRepoTopicBar() {
3941
viewDiv.children('.topic').remove();
4042
if (topics.length) {
4143
const topicArray = topics.split(',');
42-
43-
const last = viewDiv.children('a').last();
4444
for (let i = 0; i < topicArray.length; i++) {
4545
const link = $('<a class="ui repo-topic large label topic"></a>');
4646
link.attr('href', `${appSubUrl}/explore/repos?q=${encodeURIComponent(topicArray[i])}&topic=1`);
4747
link.text(topicArray[i]);
48-
link.insertBefore(last);
48+
link.insertBefore(mgrBtn); // insert all new topics before manage button
4949
}
5050
}
5151
hideElem(editDiv);
@@ -86,9 +86,6 @@ export function initRepoTopicBar() {
8686
duration: 200,
8787
variation: false,
8888
},
89-
className: {
90-
label: 'ui small label'
91-
},
9289
apiSettings: {
9390
url: `${appSubUrl}/explore/topics/search?q={query}`,
9491
throttle: 500,
@@ -101,7 +98,7 @@ export function initRepoTopicBar() {
10198
const query = stripTags(this.urlData.query.trim());
10299
let found_query = false;
103100
const current_topics = [];
104-
topicDropdown.find('div.label.visible.topic,a.label.visible').each((_, el) => {
101+
topicDropdown.find('a.label.visible').each((_, el) => {
105102
current_topics.push(el.getAttribute('data-value'));
106103
});
107104

web_src/js/index.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,15 @@ import {initFormattingReplacements} from './features/formatting.js';
8888
import {initCopyContent} from './features/copycontent.js';
8989
import {initCaptcha} from './features/captcha.js';
9090
import {initRepositoryActionView} from './components/RepoActionView.vue';
91-
import {initAriaCheckboxPatch} from './modules/aria/checkbox.js';
92-
import {initAriaDropdownPatch} from './modules/aria/dropdown.js';
9391
import {initGlobalTooltips} from './modules/tippy.js';
92+
import {initGiteaFomantic} from './modules/fomantic.js';
9493

9594
// Run time-critical code as soon as possible. This is safe to do because this
9695
// script appears at the end of <body> and rendered HTML is accessible at that point.
96+
// TODO: replace them with CustomElements
9797
initFormattingReplacements();
98-
99-
// Silence fomantic's error logging when tabs are used without a target content element
100-
$.fn.tab.settings.silent = true;
101-
// Disable the behavior of fomantic to toggle the checkbox when you press enter on a checkbox element.
102-
$.fn.checkbox.settings.enableEnterKey = false;
103-
// Use the patches to improve accessibility, these patches are designed to be as independent as possible, make it easy to modify or remove in the future.
104-
initAriaCheckboxPatch();
105-
initAriaDropdownPatch();
98+
// Init Gitea's Fomantic settings
99+
initGiteaFomantic();
106100

107101
$(document).ready(() => {
108102
initGlobalCommon();

web_src/js/modules/fomantic.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import $ from 'jquery';
2+
import {initAriaCheckboxPatch} from './aria/checkbox.js';
3+
import {initAriaDropdownPatch} from './aria/dropdown.js';
4+
import {svg} from '../svg.js';
5+
6+
export function initGiteaFomantic() {
7+
// Silence fomantic's error logging when tabs are used without a target content element
8+
$.fn.tab.settings.silent = true;
9+
// Disable the behavior of fomantic to toggle the checkbox when you press enter on a checkbox element.
10+
$.fn.checkbox.settings.enableEnterKey = false;
11+
12+
// Prevent Fomantic from guessing the popup direction.
13+
// Otherwise, if the viewport height is small, Fomantic would show the popup upward,
14+
// if the dropdown is at the beginning of the page, then the top part would be clipped by the window view, eg: Issue List "Sort" dropdown
15+
$.fn.dropdown.settings.direction = 'downward';
16+
// By default, use "exact match" for full text search
17+
$.fn.dropdown.settings.fullTextSearch = 'exact';
18+
// Do not use "cursor: pointer" for dropdown labels
19+
$.fn.dropdown.settings.className.label += ' gt-cursor-default';
20+
// Always use Gitea's SVG icons
21+
$.fn.dropdown.settings.templates.label = function(_value, text, preserveHTML, className) {
22+
const escape = $.fn.dropdown.settings.templates.escape;
23+
return escape(text, preserveHTML) + svg('octicon-x', 16, `${className.delete} icon`);
24+
};
25+
26+
// Use the patches to improve accessibility, these patches are designed to be as independent as possible, make it easy to modify or remove in the future.
27+
initAriaCheckboxPatch();
28+
initAriaDropdownPatch();
29+
}

0 commit comments

Comments
 (0)