in app/assets/javascripts/merge_request_tabs.js [163:271]
cancelButtons: $(el).find('.js-cancel-fork-suggestion-button'),
suggestionSections: $(el).find('.js-file-fork-suggestion-section'),
actionTextPieces: $(el).find('.js-file-fork-suggestion-section-action'),
}).init();
});
});
}
export function toggleLoader(state) {
$('.mr-loading-status .loading').toggleClass('hide', !state);
}
export function getActionFromHref(pathName) {
let action = pathName.match(/\/(\d+)\/(commits|diffs|pipelines|reports).*$/);
if (action) {
action = action.at(-1).replace(/(^\/|\.html)/g, '');
} else {
action = 'show';
}
return action;
}
export const pageBundles = {
show: () => import(/* webpackPrefetch: true */ '~/mr_notes/mount_app'),
diffs: () => import(/* webpackPrefetch: true */ '~/diffs'),
reports: () => import('~/merge_requests/reports'),
};
export default class MergeRequestTabs {
constructor({ action, setUrl, stubLocation, createRapidDiffsApp } = {}) {
const containers = document.querySelectorAll('.content-wrapper .container-fluid');
this.contentWrapper = containers[containers.length - 1];
this.mergeRequestTabs = document.querySelector('.merge-request-tabs-container');
this.mergeRequestTabsAll =
this.mergeRequestTabs && this.mergeRequestTabs.querySelectorAll
? this.mergeRequestTabs.querySelectorAll('.merge-request-tabs li')
: null;
this.mergeRequestTabPanes = document.querySelector('#diff-notes-app');
this.mergeRequestTabPanesAll =
this.mergeRequestTabPanes && this.mergeRequestTabPanes.querySelectorAll
? this.mergeRequestTabPanes.querySelectorAll('.tab-pane')
: null;
this.navbar = document.querySelector('.navbar-gitlab');
this.peek = document.getElementById('js-peek');
this.sidebar = document.querySelector('.js-right-sidebar');
this.pageLayout = document.querySelector('.layout-page');
this.expandSidebar = document.querySelectorAll('.js-expand-sidebar, .js-sidebar-toggle');
this.paddingTop = 16;
this.actionRegex = /\/(commits|diffs|pipelines|reports(?:\/[^/]+)?)(\.html)?\/?$/;
this.scrollPositions = {};
this.commitsTab = document.querySelector('.tab-content .commits.tab-pane');
this.currentTab = null;
this.diffsLoaded = false;
this.diffsClass = null;
this.commitsLoaded = false;
this.isFixedLayoutPreferred = this.contentWrapper.classList.contains('container-limited');
this.createRapidDiffsApp = createRapidDiffsApp;
this.rapidDiffsApp = null;
this.eventHub = createEventHub();
this.loadedPages = { [action]: true };
this.setUrl = setUrl !== undefined ? setUrl : true;
this.setCurrentAction = this.setCurrentAction.bind(this);
this.switchViewType = this.switchViewType.bind(this);
this.tabShown = this.tabShown.bind(this);
this.clickTab = this.clickTab.bind(this);
if (stubLocation) {
location = stubLocation;
}
this.bindEvents();
this.mergeRequestTabs?.querySelector(`a[data-action='${action}']`)?.click?.();
}
bindEvents() {
$('.merge-request-tabs a[data-toggle="tabvue"]').on('click', this.clickTab);
window.addEventListener('popstate', (event) => {
if (event?.state?.skipScrolling) return;
const action = getActionFromHref(window.location.pathname);
this.tabShown(action, location.href);
this.eventHub.$emit('MergeRequestTabChange', action);
});
this.eventHub.$on('diff:switch-view-type', this.switchViewType);
}
// Used in tests
unbindEvents() {
$('.merge-request-tabs a[data-toggle="tabvue"]').off('click', this.clickTab);
this.eventHub.$off('diff:switch-view-type', this.switchViewType);
}
storeScroll() {
if (this.currentTab) {
this.scrollPositions[this.currentTab] = document.documentElement.scrollTop;
}
}
recallScroll(action) {
const storedPosition = this.scrollPositions[action];
if (storedPosition == null) return;
setTimeout(() => {
window.scrollTo({