diff --git a/web_src/js/features/repo-commit.js b/web_src/js/features/repo-commit.js index fc70ba41e4..7e2f6fa58e 100644 --- a/web_src/js/features/repo-commit.js +++ b/web_src/js/features/repo-commit.js @@ -1,70 +1,70 @@ -import $ from 'jquery'; import {createTippy} from '../modules/tippy.js'; import {toggleElem} from '../utils/dom.js'; - -const {csrfToken} = window.config; +import {parseDom} from '../utils.js'; +import {POST} from '../modules/fetch.js'; export function initRepoEllipsisButton() { - $('.js-toggle-commit-body').on('click', function (e) { - e.preventDefault(); - const expanded = $(this).attr('aria-expanded') === 'true'; - toggleElem($(this).parent().find('.commit-body')); - $(this).attr('aria-expanded', String(!expanded)); - }); + for (const button of document.querySelectorAll('.js-toggle-commit-body')) { + button.addEventListener('click', function (e) { + e.preventDefault(); + const expanded = this.getAttribute('aria-expanded') === 'true'; + toggleElem(this.parentElement.querySelector('.commit-body')); + this.setAttribute('aria-expanded', String(!expanded)); + }); + } } -export function initRepoCommitLastCommitLoader() { - const notReadyEls = document.querySelectorAll('table#repo-files-table tr.notready'); - if (!notReadyEls.length) return; - +export async function initRepoCommitLastCommitLoader() { const entryMap = {}; - const entries = []; - for (const el of notReadyEls) { - const entryname = el.getAttribute('data-entryname'); - entryMap[entryname] = $(el); - entries.push(entryname); - } - const lastCommitLoaderURL = $('table#repo-files-table').data('lastCommitLoaderUrl'); + const entries = Array.from(document.querySelectorAll('table#repo-files-table tr.notready'), (el) => { + const entryName = el.getAttribute('data-entryname'); + entryMap[entryName] = el; + return entryName; + }); - if (entries.length > 200) { - $.post(lastCommitLoaderURL, { - _csrf: csrfToken, - }, (data) => { - $('table#repo-files-table').replaceWith(data); - }); + if (entries.length === 0) { return; } - $.post(lastCommitLoaderURL, { - _csrf: csrfToken, - 'f': entries, - }, (data) => { - $(data).find('tr').each((_, row) => { - if (row.className === 'commit-list') { - $('table#repo-files-table .commit-list').replaceWith(row); - return; - } - // there are other