Commit 4ffbed29 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch 'jnnkl-remove-eventlistener-main-js' into 'master'

Remove obsolete DOMContentLoadedEventListener

See merge request gitlab-org/gitlab!66823
parents 55d8a43c 78af339a
......@@ -131,27 +131,26 @@ function deferredInitialisation() {
setTimeout(() => $body.addClass('page-initialised'), 1000);
}
document.addEventListener('DOMContentLoaded', () => {
const $body = $('body');
const $document = $(document);
const bootstrapBreakpoint = bp.getBreakpointSize();
const $body = $('body');
const $document = $(document);
const bootstrapBreakpoint = bp.getBreakpointSize();
initUserTracking();
initLayoutNav();
initAlertHandler();
initUserTracking();
initLayoutNav();
initAlertHandler();
// Set the default path for all cookies to GitLab's root directory
Cookies.defaults.path = gon.relative_url_root || '/';
// Set the default path for all cookies to GitLab's root directory
Cookies.defaults.path = gon.relative_url_root || '/';
// `hashchange` is not triggered when link target is already in window.location
$body.on('click', 'a[href^="#"]', function clickHashLinkCallback() {
// `hashchange` is not triggered when link target is already in window.location
$body.on('click', 'a[href^="#"]', function clickHashLinkCallback() {
const href = this.getAttribute('href');
if (href.substr(1) === getLocationHash()) {
setTimeout(handleLocationHash, 1);
}
});
});
/**
/**
* TODO: Apparently we are collapsing the right sidebar on certain screensizes per default
* except on issue board pages. Why can't we do it with CSS?
*
......@@ -160,8 +159,8 @@ document.addEventListener('DOMContentLoaded', () => {
*
* Quick fix: Get rid of jQuery for this implementation
*/
const isBoardsPage = /(projects|groups):boards:show/.test(document.body.dataset.page);
if (!isBoardsPage && (bootstrapBreakpoint === 'sm' || bootstrapBreakpoint === 'xs')) {
const isBoardsPage = /(projects|groups):boards:show/.test(document.body.dataset.page);
if (!isBoardsPage && (bootstrapBreakpoint === 'sm' || bootstrapBreakpoint === 'xs')) {
const $rightSidebar = $('aside.right-sidebar');
const $layoutPage = $('.layout-page');
......@@ -171,10 +170,10 @@ document.addEventListener('DOMContentLoaded', () => {
} else {
$layoutPage.removeClass('right-sidebar-expanded right-sidebar-collapsed');
}
}
}
// prevent default action for disabled buttons
$('.btn').click(function clickDisabledButtonCallback(e) {
// prevent default action for disabled buttons
$('.btn').click(function clickDisabledButtonCallback(e) {
if ($(this).hasClass('disabled')) {
e.preventDefault();
e.stopImmediatePropagation();
......@@ -182,17 +181,17 @@ document.addEventListener('DOMContentLoaded', () => {
}
return true;
});
});
localTimeAgo(document.querySelectorAll('abbr.timeago, .js-timeago'), true);
localTimeAgo(document.querySelectorAll('abbr.timeago, .js-timeago'), true);
/**
/**
* This disables form buttons while a form is submitting
* We do not difinitively know all of the places where this is used
*
* TODO: Defer execution, migrate to behaviors, and add sentry logging
*/
$body.on('ajax:complete, ajax:beforeSend, submit', 'form', function ajaxCompleteCallback(e) {
$body.on('ajax:complete, ajax:beforeSend, submit', 'form', function ajaxCompleteCallback(e) {
const $buttons = $('[type="submit"], .js-disable-on-submit', this).not('.js-no-auto-disable');
switch (e.type) {
case 'ajax:beforeSend':
......@@ -201,29 +200,29 @@ document.addEventListener('DOMContentLoaded', () => {
default:
return $buttons.enable();
}
});
});
$('.navbar-toggler').on('click', () => {
$('.navbar-toggler').on('click', () => {
// The order is important. The `menu-expanded` is used as a source of truth for now.
// This can be simplified when the :combined_menu feature flag is removed.
// https://gitlab.com/gitlab-org/gitlab/-/issues/333180
$('.header-content').toggleClass('menu-expanded');
navEventHub.$emit(EVENT_RESPONSIVE_TOGGLE);
});
});
/**
/**
* Show suppressed commit diff
*
* TODO: Move to commit diff pages
*/
$document.on('click', '.diff-content .js-show-suppressed-diff', function showDiffCallback() {
$document.on('click', '.diff-content .js-show-suppressed-diff', function showDiffCallback() {
const $container = $(this).parent();
$container.next('table').show();
$container.remove();
});
});
// Show/hide comments on diff
$body.on('click', '.js-toggle-diff-comments', function toggleDiffCommentsCallback(e) {
// Show/hide comments on diff
$body.on('click', '.js-toggle-diff-comments', function toggleDiffCommentsCallback(e) {
const $this = $(this);
const notesHolders = $this.closest('.diff-file').find('.notes_holder');
......@@ -238,9 +237,9 @@ document.addEventListener('DOMContentLoaded', () => {
}
$(document).trigger('toggle.comments');
});
});
$('form.filter-form').on('submit', function filterFormSubmitCallback(event) {
$('form.filter-form').on('submit', function filterFormSubmitCallback(event) {
const link = document.createElement('a');
link.href = this.action;
......@@ -249,20 +248,19 @@ document.addEventListener('DOMContentLoaded', () => {
event.preventDefault();
// eslint-disable-next-line no-jquery/no-serialize
visitUrl(`${action}${$(this).serialize()}`);
});
});
const flashContainer = document.querySelector('.flash-container');
const flashContainer = document.querySelector('.flash-container');
if (flashContainer && flashContainer.children.length) {
if (flashContainer && flashContainer.children.length) {
flashContainer
.querySelectorAll('.flash-alert, .flash-notice, .flash-success')
.forEach((flashEl) => {
removeFlashClickListener(flashEl);
});
}
}
// initialize field errors
$('.gl-show-field-errors').each((i, form) => new GlFieldErrors(form));
// initialize field errors
$('.gl-show-field-errors').each((i, form) => new GlFieldErrors(form));
requestIdleCallback(deferredInitialisation);
});
requestIdleCallback(deferredInitialisation);
Markdown is supported
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