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

repo-commit.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import $ from 'jquery';
  2. import {createTippy} from '../modules/tippy.js';
  3. import {toggleElem} from '../utils/dom.js';
  4. const {csrfToken} = window.config;
  5. export function initRepoEllipsisButton() {
  6. $('.ellipsis-button').on('click', function (e) {
  7. e.preventDefault();
  8. const expanded = $(this).attr('aria-expanded') === 'true';
  9. toggleElem($(this).parent().find('.commit-body'));
  10. $(this).attr('aria-expanded', String(!expanded));
  11. });
  12. }
  13. export function initRepoCommitLastCommitLoader() {
  14. const entryMap = {};
  15. const entries = $('table#repo-files-table tr.notready')
  16. .map((_, v) => {
  17. entryMap[$(v).attr('data-entryname')] = $(v);
  18. return $(v).attr('data-entryname');
  19. })
  20. .get();
  21. if (entries.length === 0) {
  22. return;
  23. }
  24. const lastCommitLoaderURL = $('table#repo-files-table').data('lastCommitLoaderUrl');
  25. if (entries.length > 200) {
  26. $.post(lastCommitLoaderURL, {
  27. _csrf: csrfToken,
  28. }, (data) => {
  29. $('table#repo-files-table').replaceWith(data);
  30. });
  31. return;
  32. }
  33. $.post(lastCommitLoaderURL, {
  34. _csrf: csrfToken,
  35. 'f': entries,
  36. }, (data) => {
  37. $(data).find('tr').each((_, row) => {
  38. if (row.className === 'commit-list') {
  39. $('table#repo-files-table .commit-list').replaceWith(row);
  40. return;
  41. }
  42. // there are other <tr> rows in response (eg: <tr class="has-parent">)
  43. // at the moment only the "data-entryname" rows should be processed
  44. const entryName = $(row).attr('data-entryname');
  45. if (entryName) {
  46. entryMap[entryName].replaceWith(row);
  47. }
  48. });
  49. });
  50. }
  51. export function initCommitStatuses() {
  52. $('.commit-statuses-trigger').each(function () {
  53. const top = $('.repository.file.list').length > 0 || $('.repository.diff').length > 0;
  54. createTippy(this, {
  55. content: this.nextElementSibling,
  56. placement: top ? 'top-start' : 'bottom-start',
  57. interactive: true,
  58. });
  59. });
  60. }