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.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 labelName = emojify.replace(label.name);
  20. const red = parseInt(label.color.substring(0, 2), 16);
  21. const green = parseInt(label.color.substring(2, 4), 16);
  22. const blue = parseInt(label.color.substring(4, 6), 16);
  23. let color = '#ffffff';
  24. if ((red * 0.299 + green * 0.587 + blue * 0.114) > 125) {
  25. color = '#000000';
  26. }
  27. labels += `<div class="ui label" style="color: ${color}; background-color:#${label.color};">${labelName}</div>`;
  28. }
  29. if (labels.length > 0) {
  30. labels = `<p>${labels}</p>`;
  31. }
  32. let octicon;
  33. if (issue.pull_request !== null) {
  34. if (issue.state === 'open') {
  35. octicon = 'green octicon-git-pull-request'; // Open PR
  36. } else if (issue.pull_request.merged === true) {
  37. octicon = 'purple octicon-git-merge'; // Merged PR
  38. } else {
  39. octicon = 'red octicon-git-pull-request'; // Closed PR
  40. }
  41. } else if (issue.state === 'open') {
  42. octicon = 'green octicon-issue-opened'; // Open Issue
  43. } else {
  44. octicon = 'red octicon-issue-closed'; // Closed Issue
  45. }
  46. $element.popup({
  47. variation: 'wide',
  48. delay: {
  49. show: 250
  50. },
  51. html: `
  52. <div>
  53. <p><small>${issue.repository.full_name} on ${createdAt}</small></p>
  54. <p><i class="octicon ${octicon}"></i> <strong>${issue.title}</strong> #${index}</p>
  55. <p>${body}</p>
  56. ${labels}
  57. </div>
  58. `
  59. });
  60. });
  61. }