Skip to content

Commit d67e9b9

Browse files
jolheisersapk
andauthored
SVG Octicon fixes (#10237)
* SVG fixes Signed-off-by: jolheiser <[email protected]> * Colorize span->svg only Signed-off-by: jolheiser <[email protected]> * @silverwind suggestions Signed-off-by: jolheiser <[email protected]> * Alphabetical Signed-off-by: jolheiser <[email protected]> * Convert suburl and staticPrefix to window.config Signed-off-by: jolheiser <[email protected]> * De-structure Signed-off-by: jolheiser <[email protected]> Co-authored-by: Antoine GIRARD <[email protected]>
1 parent 2399bad commit d67e9b9

File tree

8 files changed

+72
-60
lines changed

8 files changed

+72
-60
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ rules:
3333
default-case: [0]
3434
func-names: [0]
3535
import/extensions: [0]
36+
import/prefer-default-export: [0]
3637
max-len: [0]
3738
newline-per-chained-call: [0]
3839
no-alert: [0]

templates/base/head.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
<meta name="keywords" content="{{MetaKeywords}}">
3737
<meta name="referrer" content="no-referrer" />
3838
<meta name="_csrf" content="{{.CsrfToken}}" />
39-
<meta name="_suburl" content="{{AppSubUrl}}" />
40-
<meta name="_staticprefix" content="{{StaticUrlPrefix}}" />
4139
{{if .IsSigned}}
4240
<meta name="_uid" content="{{.SignedUser.ID}}" />
4341
{{end}}
@@ -86,6 +84,8 @@
8684
</script>
8785
<script>
8886
window.config = {
87+
AppSubUrl: '{{AppSubUrl}}',
88+
StaticUrlPrefix: '{{StaticUrlPrefix}}',
8989
Datetimepicker: {{if .RequireDatetimepicker}}true{{else}}false{{end}},
9090
Dropzone: {{if .RequireDropzone}}true{{else}}false{{end}},
9191
HighlightJS: {{if .RequireHighlightJS}}true{{else}}false{{end}},

templates/repo/issue/view_title.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{{end}}
1818
</div>
1919
{{if .HasMerged}}
20-
<div class="ui purple large label">{{svg "octicon-gt-pull-request" 16}} {{.i18n.Tr "repo.pulls.merged"}}</div>
20+
<div class="ui purple large label">{{svg "octicon-git-pull-request" 16}} {{.i18n.Tr "repo.pulls.merged"}}</div>
2121
{{else if .Issue.IsClosed}}
2222
<div class="ui red large label">{{svg "octicon-issue-closed" 16}} {{.i18n.Tr "repo.issues.closed_title"}}</div>
2323
{{else if .Issue.IsPull}}

web_src/js/features/contextPopup.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
export default function initContextPopups(suburl) {
1+
import { svg } from '../utils.js';
2+
3+
const { AppSubUrl } = window.config;
4+
5+
export default function initContextPopups() {
26
const refIssues = $('.ref-issue');
37
if (!refIssues.length) return;
48

59
refIssues.each(function () {
610
const [index, _issues, repo, owner] = $(this).attr('href').replace(/[#?].*$/, '').split('/').reverse();
7-
issuePopup(suburl, owner, repo, index, $(this));
11+
issuePopup(owner, repo, index, $(this));
812
});
913
}
1014

11-
function issuePopup(suburl, owner, repo, index, $element) {
12-
$.get(`${suburl}/api/v1/repos/${owner}/${repo}/issues/${index}`, (issue) => {
15+
function issuePopup(owner, repo, index, $element) {
16+
$.get(`${AppSubUrl}/api/v1/repos/${owner}/${repo}/issues/${index}`, (issue) => {
1317
const createdAt = new Date(issue.created_at).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });
1418

1519
let body = issue.body.replace(/\n+/g, ' ');
@@ -34,19 +38,24 @@ function issuePopup(suburl, owner, repo, index, $element) {
3438
labels = `<p>${labels}</p>`;
3539
}
3640

37-
let octicon;
41+
let octicon, color;
3842
if (issue.pull_request !== null) {
3943
if (issue.state === 'open') {
40-
octicon = 'green octicon-git-pull-request'; // Open PR
44+
color = 'green';
45+
octicon = 'octicon-git-pull-request'; // Open PR
4146
} else if (issue.pull_request.merged === true) {
42-
octicon = 'purple octicon-git-merge'; // Merged PR
47+
color = 'purple';
48+
octicon = 'octicon-git-merge'; // Merged PR
4349
} else {
44-
octicon = 'red octicon-git-pull-request'; // Closed PR
50+
color = 'red';
51+
octicon = 'octicon-git-pull-request'; // Closed PR
4552
}
4653
} else if (issue.state === 'open') {
47-
octicon = 'green octicon-issue-opened'; // Open Issue
54+
color = 'green';
55+
octicon = 'octicon-issue-opened'; // Open Issue
4856
} else {
49-
octicon = 'red octicon-issue-closed'; // Closed Issue
57+
color = 'red';
58+
octicon = 'octicon-issue-closed'; // Closed Issue
5059
}
5160

5261
$element.popup({
@@ -57,7 +66,7 @@ function issuePopup(suburl, owner, repo, index, $element) {
5766
html: `
5867
<div>
5968
<p><small>${issue.repository.full_name} on ${createdAt}</small></p>
60-
<p><i class="octicon ${octicon}"></i> <strong>${issue.title}</strong> #${index}</p>
69+
<p><span class="${color}">${svg(octicon, 16)}</span> <strong>${issue.title}</strong> #${index}</p>
6170
<p>${body}</p>
6271
${labels}
6372
</div>

web_src/js/index.js

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'jquery.are-you-sure';
66
import './publicPath.js';
77
import './polyfills.js';
88
import './vendor/semanticDropdown.js';
9+
import { svg } from './utils.js';
910

1011
import initContextPopups from './features/contextPopup.js';
1112
import initHighlight from './features/highlight.js';
@@ -14,17 +15,13 @@ import initClipboard from './features/clipboard.js';
1415

1516
import ActivityTopAuthors from './components/ActivityTopAuthors.vue';
1617

18+
const { AppSubUrl, StaticUrlPrefix } = window.config;
19+
1720
function htmlEncode(text) {
1821
return jQuery('<div />').text(text).html();
1922
}
2023

21-
function svg(name, size) {
22-
return `<svg class="svg ${name}" width="${size}" height="${size}" aria-hidden="true"><use xlink:href="${staticPrefix}/img/svg/icons.svg#${name}"/></svg>`;
23-
}
24-
2524
let csrf;
26-
let suburl;
27-
let staticPrefix;
2825
let previewFileModes;
2926
let simpleMDEditor;
3027
const commentMDEditors = {};
@@ -157,7 +154,7 @@ function initRepoStatusChecker() {
157154
}
158155
$.ajax({
159156
type: 'GET',
160-
url: `${suburl}/${repo_name}/status`,
157+
url: `${AppSubUrl}/${repo_name}/status`,
161158
data: {
162159
_csrf: csrf,
163160
},
@@ -293,7 +290,7 @@ function uploadFile(file, callback) {
293290
}
294291
};
295292

296-
xhr.open('post', `${suburl}/attachments`, true);
293+
xhr.open('post', `${AppSubUrl}/attachments`, true);
297294
xhr.setRequestHeader('X-Csrf-Token', csrf);
298295
const formData = new FormData();
299296
formData.append('file', file, file.name);
@@ -313,7 +310,7 @@ function initImagePaste(target) {
313310
insertAtCursor(field, `![${name}]()`);
314311
uploadFile(img, (res) => {
315312
const data = JSON.parse(res);
316-
replaceAndKeepCursor(field, `![${name}]()`, `![${name}](${suburl}/attachments/${data.uuid})`);
313+
replaceAndKeepCursor(field, `![${name}]()`, `![${name}](${AppSubUrl}/attachments/${data.uuid})`);
317314
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
318315
$('.files').append(input);
319316
});
@@ -329,7 +326,7 @@ function initSimpleMDEImagePaste(simplemde, files) {
329326
uploadFile(img, (res) => {
330327
const data = JSON.parse(res);
331328
const pos = simplemde.codemirror.getCursor();
332-
simplemde.codemirror.replaceRange(`![${name}](${suburl}/attachments/${data.uuid})`, pos);
329+
simplemde.codemirror.replaceRange(`![${name}](${AppSubUrl}/attachments/${data.uuid})`, pos);
333330
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
334331
files.append(input);
335332
});
@@ -2059,7 +2056,7 @@ function searchUsers() {
20592056
$searchUserBox.search({
20602057
minCharacters: 2,
20612058
apiSettings: {
2062-
url: `${suburl}/api/v1/users/search?q={query}`,
2059+
url: `${AppSubUrl}/api/v1/users/search?q={query}`,
20632060
onResponse(response) {
20642061
const items = [];
20652062
$.each(response.data, (_i, item) => {
@@ -2086,7 +2083,7 @@ function searchTeams() {
20862083
$searchTeamBox.search({
20872084
minCharacters: 2,
20882085
apiSettings: {
2089-
url: `${suburl}/api/v1/orgs/${$searchTeamBox.data('org')}/teams/search?q={query}`,
2086+
url: `${AppSubUrl}/api/v1/orgs/${$searchTeamBox.data('org')}/teams/search?q={query}`,
20902087
headers: { 'X-Csrf-Token': csrf },
20912088
onResponse(response) {
20922089
const items = [];
@@ -2110,7 +2107,7 @@ function searchRepositories() {
21102107
$searchRepoBox.search({
21112108
minCharacters: 2,
21122109
apiSettings: {
2113-
url: `${suburl}/api/v1/repos/search?q={query}&uid=${$searchRepoBox.data('uid')}`,
2110+
url: `${AppSubUrl}/api/v1/repos/search?q={query}&uid=${$searchRepoBox.data('uid')}`,
21142111
onResponse(response) {
21152112
const items = [];
21162113
$.each(response.data, (_i, item) => {
@@ -2180,7 +2177,7 @@ function initU2FAuth() {
21802177
}
21812178
u2fApi.ensureSupport()
21822179
.then(() => {
2183-
$.getJSON(`${suburl}/user/u2f/challenge`).success((req) => {
2180+
$.getJSON(`${AppSubUrl}/user/u2f/challenge`).success((req) => {
21842181
u2fApi.sign(req.appId, req.challenge, req.registeredKeys, 30)
21852182
.then(u2fSigned)
21862183
.catch((err) => {
@@ -2193,12 +2190,12 @@ function initU2FAuth() {
21932190
});
21942191
}).catch(() => {
21952192
// Fallback in case browser do not support U2F
2196-
window.location.href = `${suburl}/user/two_factor`;
2193+
window.location.href = `${AppSubUrl}/user/two_factor`;
21972194
});
21982195
}
21992196
function u2fSigned(resp) {
22002197
$.ajax({
2201-
url: `${suburl}/user/u2f/sign`,
2198+
url: `${AppSubUrl}/user/u2f/sign`,
22022199
type: 'POST',
22032200
headers: { 'X-Csrf-Token': csrf },
22042201
data: JSON.stringify(resp),
@@ -2215,7 +2212,7 @@ function u2fRegistered(resp) {
22152212
return;
22162213
}
22172214
$.ajax({
2218-
url: `${suburl}/user/settings/security/u2f/register`,
2215+
url: `${AppSubUrl}/user/settings/security/u2f/register`,
22192216
type: 'POST',
22202217
headers: { 'X-Csrf-Token': csrf },
22212218
data: JSON.stringify(resp),
@@ -2274,7 +2271,7 @@ function initU2FRegister() {
22742271
}
22752272

22762273
function u2fRegisterRequest() {
2277-
$.post(`${suburl}/user/settings/security/u2f/request_register`, {
2274+
$.post(`${AppSubUrl}/user/settings/security/u2f/request_register`, {
22782275
_csrf: csrf,
22792276
name: $('#nickname').val()
22802277
}).success((req) => {
@@ -2337,7 +2334,7 @@ function initTemplateSearch() {
23372334
$('#repo_template_search')
23382335
.dropdown({
23392336
apiSettings: {
2340-
url: `${suburl}/api/v1/repos/search?q={query}&template=true&priority_owner_id=${$('#uid').val()}`,
2337+
url: `${AppSubUrl}/api/v1/repos/search?q={query}&template=true&priority_owner_id=${$('#uid').val()}`,
23412338
onResponse(response) {
23422339
const filteredResponse = { success: true, results: [] };
23432340
filteredResponse.results.push({
@@ -2365,8 +2362,6 @@ function initTemplateSearch() {
23652362

23662363
$(document).ready(async () => {
23672364
csrf = $('meta[name=_csrf]').attr('content');
2368-
suburl = $('meta[name=_suburl]').attr('content');
2369-
staticPrefix = $('meta[name=_staticprefix]').attr('content');
23702365

23712366
// Show exact time
23722367
$('.time-since').each(function () {
@@ -2455,7 +2450,7 @@ $(document).ready(async () => {
24552450

24562451
// Emojify
24572452
emojify.setConfig({
2458-
img_dir: `${suburl}/vendor/plugins/emojify/images`,
2453+
img_dir: `${AppSubUrl}/vendor/plugins/emojify/images`,
24592454
ignore_emoticons: true
24602455
});
24612456
const hasEmoji = document.getElementsByClassName('has-emoji');
@@ -2575,7 +2570,7 @@ $(document).ready(async () => {
25752570
initPullRequestReview();
25762571
initRepoStatusChecker();
25772572
initTemplateSearch();
2578-
initContextPopups(suburl);
2573+
initContextPopups();
25792574

25802575
// Repo clone url.
25812576
if ($('#repo-clone-url').length > 0) {
@@ -2785,7 +2780,7 @@ function initVueComponents() {
27852780
reposFilter: 'all',
27862781
searchQuery: '',
27872782
isLoading: false,
2788-
staticPrefix,
2783+
staticPrefix: StaticUrlPrefix,
27892784
repoTypes: {
27902785
all: {
27912786
count: 0,
@@ -2891,6 +2886,8 @@ function initVueComponents() {
28912886
return 'octicon-repo-forked';
28922887
} if (repo.mirror) {
28932888
return 'octicon-repo-clone';
2889+
} if (repo.template) {
2890+
return `octicon-repo-template${repo.private ? '-private' : ''}`;
28942891
} if (repo.private) {
28952892
return 'octicon-lock';
28962893
}
@@ -2921,7 +2918,7 @@ function initVueApp() {
29212918
el,
29222919
data: {
29232920
searchLimit: (document.querySelector('meta[name=_search_limit]') || {}).content,
2924-
suburl: document.querySelector('meta[name=_suburl]').content,
2921+
suburl: AppSubUrl,
29252922
uid: Number((document.querySelector('meta[name=_context_uid]') || {}).content),
29262923
activityTopAuthors: window.ActivityTopAuthors || [],
29272924
},
@@ -3037,7 +3034,7 @@ window.initHeatmap = function (appElementId, heatmapUser, locale) {
30373034
el,
30383035

30393036
data: {
3040-
suburl: document.querySelector('meta[name=_suburl]').content,
3037+
suburl: AppSubUrl,
30413038
heatmapUser,
30423039
locale
30433040
},
@@ -3283,7 +3280,7 @@ function initTopicbar() {
32833280
const last = viewDiv.children('a').last();
32843281
for (let i = 0; i < topicArray.length; i++) {
32853282
const link = $('<a class="ui repo-topic small label topic"></a>');
3286-
link.attr('href', `${suburl}/explore/repos?q=${encodeURIComponent(topicArray[i])}&topic=1`);
3283+
link.attr('href', `${AppSubUrl}/explore/repos?q=${encodeURIComponent(topicArray[i])}&topic=1`);
32873284
link.text(topicArray[i]);
32883285
link.insertBefore(last);
32893286
}
@@ -3331,7 +3328,7 @@ function initTopicbar() {
33313328
label: 'ui small label'
33323329
},
33333330
apiSettings: {
3334-
url: `${suburl}/api/v1/topics/search?q={query}`,
3331+
url: `${AppSubUrl}/api/v1/topics/search?q={query}`,
33353332
throttle: 500,
33363333
cache: false,
33373334
onResponse(res) {
@@ -3488,9 +3485,9 @@ function initIssueList() {
34883485
const repoId = $('#repoId').val();
34893486
const crossRepoSearch = $('#crossRepoSearch').val();
34903487
const tp = $('#type').val();
3491-
let issueSearchUrl = `${suburl}/api/v1/repos/${repolink}/issues?q={query}&type=${tp}`;
3488+
let issueSearchUrl = `${AppSubUrl}/api/v1/repos/${repolink}/issues?q={query}&type=${tp}`;
34923489
if (crossRepoSearch === 'true') {
3493-
issueSearchUrl = `${suburl}/api/v1/repos/issues/search?q={query}&priority_repo_id=${repoId}&type=${tp}`;
3490+
issueSearchUrl = `${AppSubUrl}/api/v1/repos/issues/search?q={query}&priority_repo_id=${repoId}&type=${tp}`;
34943491
}
34953492
$('#new-dependency-drop-list')
34963493
.dropdown({

web_src/js/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { StaticUrlPrefix } = window.config;
2+
3+
export function svg(name, size) {
4+
return `<svg class="svg ${name}" width="${size}" height="${size}" aria-hidden="true"><use xlink:href="${StaticUrlPrefix}/img/svg/icons.svg#${name}"/></svg>`;
5+
}

web_src/less/_base.less

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,13 +1168,13 @@ i.icon.centerlock {
11681168
}
11691169

11701170
.svg {
1171-
&.green {
1171+
span.green & {
11721172
color: #21ba45;
11731173
}
1174-
&.red {
1174+
span.red & {
11751175
color: #db2828;
11761176
}
1177-
&.purple {
1177+
span.purple & {
11781178
color: #a333c8;
11791179
}
11801180
}

0 commit comments

Comments
 (0)