Commit edbc1cc4 authored by drumm's avatar drumm
Browse files

Issue #3264662 by crawleyhost, drumm: Add “Toggle commit list” control to long...

Issue #3264662 by crawleyhost, drumm: Add “Toggle commit list” control to long merge request commit listings
parent 06c06a65
......@@ -326,7 +326,7 @@
'!id': noteElement.getAttribute('id'),
'!post': post
}) + '<div class="merge-request-note">' + note.bodyHtml + '</div>';
postProcessGitLabHtml(noteElement.querySelector('.merge-request-note'), projectPath);
postProcessGitLabHtml(noteElement.querySelector('.merge-request-note'), projectPath, note);
// Test results.
for (let commitElement of noteElement.querySelectorAll('.gfm-commit[data-commit]:first-child')) {
insertTestResults(mergeRequestData.sourceBranch, commitElement.dataset.commit, commitElement.parentElement, 'afterend', mergeRequestData);
......@@ -443,7 +443,7 @@
return commentList;
}
function postProcessGitLabHtml(element, projectPath) {
function postProcessGitLabHtml(element, projectPath, note = null) {
// Add the GitLab domain for links & images.
for (let link of element.querySelectorAll('a[href^="/"]:not([href^="//"])')) {
link.setAttribute('href', Drupal.settings.drupalorgGitlabUrl + link.getAttribute('href'));
......@@ -455,6 +455,29 @@
image.setAttribute('src', Drupal.settings.drupalorgGitlabUrl + match[0]);
}
}
// Add Show all/fewer commits toggle.
if (note !== null && note.system) {
const commitList = element.querySelector(':scope > ul');
if (commitList !== null && commitList.childElementCount > 3) {
element.classList.add('drupalorg-inline-collapsible');
// Create see more button & place.
const seeMore = document.createElement('button');
seeMore.classList.add('see-more');
element.insertAdjacentElement('beforeend', seeMore);
seeMore.addEventListener('click', function (e) {
if (commitList.classList.contains('collapsed')) {
this.innerHTML= Drupal.t("Show fewer commits");
commitList.classList.remove('collapsed');
}
else {
this.innerHTML = Drupal.t("Show all commits");
commitList.classList.add('collapsed');
}
});
seeMore.click();
}
}
}
function insertTestResults(branch, commit, element, position, mergeRequestData) {
......@@ -485,4 +508,24 @@
element.insertAdjacentHTML(position, content);
}
// See more (org pages for now)
const collapsibles = Array.from(document.querySelectorAll('.drupalorg-inline-collapsible'));
for (var i = 0; i < collapsibles.length; i++) {
const seeMore = document.createElement('button');
seeMore.classList.add('see-more');
collapsibles[i].insertAdjacentElement('beforeend', seeMore);
seeMore.addEventListener('click', function (e) {
const classes = e.target.previousSibling.classList;
if (classes.contains('collapsed')) {
this.innerHTML= Drupal.t(" - See less");
classes.remove('collapsed');
}
else {
this.innerHTML = Drupal.t(" + See more");
classes.add('collapsed');
}
});
seeMore.click();
}
})();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment