2022-01-29 05:00:11 +08:00
|
|
|
import $ from 'jquery';
|
2022-08-09 20:37:34 +08:00
|
|
|
import {createTippy} from '../modules/tippy.js';
|
2022-01-29 05:00:11 +08:00
|
|
|
|
2021-11-09 17:27:25 +08:00
|
|
|
const {csrfToken} = window.config;
|
|
|
|
|
2021-11-23 10:44:38 +08:00
|
|
|
export function initRepoEllipsisButton() {
|
|
|
|
$('.ellipsis-button').on('click', function (e) {
|
2021-10-17 01:28:04 +08:00
|
|
|
e.preventDefault();
|
2021-11-23 10:44:38 +08:00
|
|
|
const expanded = $(this).attr('aria-expanded') === 'true';
|
2021-10-17 01:28:04 +08:00
|
|
|
$(this).parent().find('.commit-body').toggle();
|
2021-11-23 10:44:38 +08:00
|
|
|
$(this).attr('aria-expanded', String(!expanded));
|
2021-10-17 01:28:04 +08:00
|
|
|
});
|
|
|
|
}
|
2021-11-09 17:27:25 +08:00
|
|
|
|
|
|
|
export function initRepoCommitLastCommitLoader() {
|
|
|
|
const entryMap = {};
|
|
|
|
|
|
|
|
const entries = $('table#repo-files-table tr.notready')
|
|
|
|
.map((_, v) => {
|
|
|
|
entryMap[$(v).attr('data-entryname')] = $(v);
|
|
|
|
return $(v).attr('data-entryname');
|
|
|
|
})
|
|
|
|
.get();
|
|
|
|
|
|
|
|
if (entries.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const lastCommitLoaderURL = $('table#repo-files-table').data('lastCommitLoaderUrl');
|
|
|
|
|
|
|
|
if (entries.length > 200) {
|
|
|
|
$.post(lastCommitLoaderURL, {
|
|
|
|
_csrf: csrfToken,
|
|
|
|
}, (data) => {
|
|
|
|
$('table#repo-files-table').replaceWith(data);
|
|
|
|
});
|
|
|
|
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;
|
|
|
|
}
|
2022-06-17 17:44:35 +08:00
|
|
|
// there are other <tr> rows in response (eg: <tr class="has-parent">)
|
|
|
|
// at the moment only the "data-entryname" rows should be processed
|
|
|
|
const entryName = $(row).attr('data-entryname');
|
|
|
|
if (entryName) {
|
|
|
|
entryMap[entryName].replaceWith(row);
|
|
|
|
}
|
2021-11-09 17:27:25 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-04-27 03:09:46 +08:00
|
|
|
|
|
|
|
export function initCommitStatuses() {
|
|
|
|
$('.commit-statuses-trigger').each(function () {
|
2022-08-10 05:55:29 +08:00
|
|
|
const top = $('.repository.file.list').length > 0 || $('.repository.diff').length > 0;
|
2022-08-09 20:37:34 +08:00
|
|
|
|
|
|
|
createTippy(this, {
|
|
|
|
trigger: 'click',
|
|
|
|
content: this.nextSibling,
|
2022-08-10 05:55:29 +08:00
|
|
|
placement: top ? 'top-start' : 'bottom-start',
|
2022-08-09 20:37:34 +08:00
|
|
|
interactive: true,
|
|
|
|
});
|
2022-04-27 03:09:46 +08:00
|
|
|
});
|
|
|
|
}
|