From d67e9b9629557df1e355f0a864792c194b3e8848 Mon Sep 17 00:00:00 2001 From: John Olheiser <42128690+jolheiser@users.noreply.github.com> Date: Tue, 11 Feb 2020 19:53:18 -0600 Subject: SVG Octicon fixes (#10237) * SVG fixes Signed-off-by: jolheiser * Colorize span->svg only Signed-off-by: jolheiser * @silverwind suggestions Signed-off-by: jolheiser * Alphabetical Signed-off-by: jolheiser * Convert suburl and staticPrefix to window.config Signed-off-by: jolheiser * De-structure Signed-off-by: jolheiser Co-authored-by: Antoine GIRARD --- web_src/js/features/contextPopup.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'web_src/js/features') diff --git a/web_src/js/features/contextPopup.js b/web_src/js/features/contextPopup.js index 34b6d50357..5acfa9c293 100644 --- a/web_src/js/features/contextPopup.js +++ b/web_src/js/features/contextPopup.js @@ -1,15 +1,19 @@ -export default function initContextPopups(suburl) { +import { svg } from '../utils.js'; + +const { AppSubUrl } = window.config; + +export default function initContextPopups() { const refIssues = $('.ref-issue'); if (!refIssues.length) return; refIssues.each(function () { const [index, _issues, repo, owner] = $(this).attr('href').replace(/[#?].*$/, '').split('/').reverse(); - issuePopup(suburl, owner, repo, index, $(this)); + issuePopup(owner, repo, index, $(this)); }); } -function issuePopup(suburl, owner, repo, index, $element) { - $.get(`${suburl}/api/v1/repos/${owner}/${repo}/issues/${index}`, (issue) => { +function issuePopup(owner, repo, index, $element) { + $.get(`${AppSubUrl}/api/v1/repos/${owner}/${repo}/issues/${index}`, (issue) => { const createdAt = new Date(issue.created_at).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' }); let body = issue.body.replace(/\n+/g, ' '); @@ -34,19 +38,24 @@ function issuePopup(suburl, owner, repo, index, $element) { labels = `

${labels}

`; } - let octicon; + let octicon, color; if (issue.pull_request !== null) { if (issue.state === 'open') { - octicon = 'green octicon-git-pull-request'; // Open PR + color = 'green'; + octicon = 'octicon-git-pull-request'; // Open PR } else if (issue.pull_request.merged === true) { - octicon = 'purple octicon-git-merge'; // Merged PR + color = 'purple'; + octicon = 'octicon-git-merge'; // Merged PR } else { - octicon = 'red octicon-git-pull-request'; // Closed PR + color = 'red'; + octicon = 'octicon-git-pull-request'; // Closed PR } } else if (issue.state === 'open') { - octicon = 'green octicon-issue-opened'; // Open Issue + color = 'green'; + octicon = 'octicon-issue-opened'; // Open Issue } else { - octicon = 'red octicon-issue-closed'; // Closed Issue + color = 'red'; + octicon = 'octicon-issue-closed'; // Closed Issue } $element.popup({ @@ -57,7 +66,7 @@ function issuePopup(suburl, owner, repo, index, $element) { html: `

${issue.repository.full_name} on ${createdAt}

-

${issue.title} #${index}

+

${svg(octicon, 16)} ${issue.title} #${index}

${body}

${labels}
-- cgit v1.2.3