code.gitea.io/gitea@v1.21.7/web_src/js/features/repo-commit.js (about)

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