You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

contextPopup.js 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. export default function initContextPopups(suburl) {
  2. const refIssues = $('.ref-issue');
  3. if (!refIssues.length) return;
  4. refIssues.each(function () {
  5. const [index, _issues, repo, owner] = $(this).attr('href').replace(/[#?].*$/, '').split('/').reverse();
  6. issuePopup(suburl, owner, repo, index, $(this));
  7. });
  8. }
  9. function issuePopup(suburl, owner, repo, index, $element) {
  10. $.get(`${suburl}/api/v1/repos/${owner}/${repo}/issues/${index}`, (issue) => {
  11. const createdAt = new Date(issue.created_at).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });
  12. let body = issue.body.replace(/\n+/g, ' ');
  13. if (body.length > 85) {
  14. body = `${body.substring(0, 85)}...`;
  15. }
  16. let labels = '';
  17. for (let i = 0; i < issue.labels.length; i++) {
  18. const label = issue.labels[i];
  19. const red = parseInt(label.color.substring(0, 2), 16);
  20. const green = parseInt(label.color.substring(2, 4), 16);
  21. const blue = parseInt(label.color.substring(4, 6), 16);
  22. let color = '#ffffff';
  23. if ((red * 0.299 + green * 0.587 + blue * 0.114) > 125) {
  24. color = '#000000';
  25. }
  26. labels += `<div class="ui label" style="color: ${color}; background-color:#${label.color};">${label.name}</div>`;
  27. }
  28. if (labels.length > 0) {
  29. labels = `<p>${labels}</p>`;
  30. }
  31. let octicon;
  32. if (issue.pull_request !== null) {
  33. if (issue.state === 'open') {
  34. octicon = 'green octicon-git-pull-request'; // Open PR
  35. } else if (issue.pull_request.merged === true) {
  36. octicon = 'purple octicon-git-merge'; // Merged PR
  37. } else {
  38. octicon = 'red octicon-git-pull-request'; // Closed PR
  39. }
  40. } else if (issue.state === 'open') {
  41. octicon = 'green octicon-issue-opened'; // Open Issue
  42. } else {
  43. octicon = 'red octicon-issue-closed'; // Closed Issue
  44. }
  45. $element.popup({
  46. variation: 'wide',
  47. delay: {
  48. show: 250
  49. },
  50. html: `
  51. <div>
  52. <p><small>${issue.repository.full_name} on ${createdAt}</small></p>
  53. <p><i class="octicon ${octicon}"></i> <strong>${issue.title}</strong> #${index}</p>
  54. <p>${body}</p>
  55. ${labels}
  56. </div>
  57. `
  58. });
  59. });
  60. }