summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/main.js')
-rw-r--r--app/assets/javascripts/main.js229
1 files changed, 110 insertions, 119 deletions
diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js
index 5c14000a2aa..1aaefcaa13b 100644
--- a/app/assets/javascripts/main.js
+++ b/app/assets/javascripts/main.js
@@ -27,7 +27,6 @@ import { getLocationHash, visitUrl } from './lib/utils/url_utility';
import initFeatureHighlight from './feature_highlight';
import LazyLoader from './lazy_loader';
import initLogoAnimation from './logo';
-import initFrequentItemDropdowns from './frequent_items';
import initBreadcrumbs from './breadcrumb';
import initPersistentUserCallouts from './persistent_user_callouts';
import { initUserTracking, initDefaultTrackers } from './tracking';
@@ -36,7 +35,6 @@ import GlFieldErrors from './gl_field_errors';
import initUserPopovers from './user_popovers';
import initBroadcastNotifications from './broadcast_notification';
import { initTopNav } from './nav';
-import navEventHub, { EVENT_RESPONSIVE_TOGGLE } from './nav/event_hub';
import 'ee_else_ce/main_ee';
@@ -92,7 +90,6 @@ function deferredInitialisation() {
initServicePingConsent();
initUserPopovers();
initBroadcastNotifications();
- initFrequentItemDropdowns();
initPersistentUserCallouts();
initDefaultTrackers();
initFeatureHighlight();
@@ -133,138 +130,132 @@ function deferredInitialisation() {
setTimeout(() => $body.addClass('page-initialised'), 1000);
}
-document.addEventListener('DOMContentLoaded', () => {
- const $body = $('body');
- const $document = $(document);
- const bootstrapBreakpoint = bp.getBreakpointSize();
-
- initUserTracking();
- initLayoutNav();
- initAlertHandler();
-
- // 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() {
- const href = this.getAttribute('href');
- if (href.substr(1) === getLocationHash()) {
- setTimeout(handleLocationHash, 1);
- }
- });
+const $body = $('body');
+const $document = $(document);
+const bootstrapBreakpoint = bp.getBreakpointSize();
+
+initUserTracking();
+initLayoutNav();
+initAlertHandler();
+
+// Set the default path for all cookies to GitLab's root directory
+Cookies.defaults.path = gon.relative_url_root || '/';
- /**
- * 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?
- *
- * Proposal: Expose a global sidebar API, which we could import wherever we are manipulating
- * the visibility of the sidebar.
- *
- * 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 $rightSidebar = $('aside.right-sidebar');
- const $layoutPage = $('.layout-page');
-
- if ($rightSidebar.length > 0) {
- $rightSidebar.removeClass('right-sidebar-expanded').addClass('right-sidebar-collapsed');
- $layoutPage.removeClass('right-sidebar-expanded').addClass('right-sidebar-collapsed');
- } else {
- $layoutPage.removeClass('right-sidebar-expanded right-sidebar-collapsed');
- }
+// `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);
}
+});
- // prevent default action for disabled buttons
- $('.btn').click(function clickDisabledButtonCallback(e) {
- if ($(this).hasClass('disabled')) {
- e.preventDefault();
- e.stopImmediatePropagation();
- return false;
- }
+/**
+ * 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?
+ *
+ * Proposal: Expose a global sidebar API, which we could import wherever we are manipulating
+ * the visibility of the sidebar.
+ *
+ * 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 $rightSidebar = $('aside.right-sidebar');
+ const $layoutPage = $('.layout-page');
+
+ if ($rightSidebar.length > 0) {
+ $rightSidebar.removeClass('right-sidebar-expanded').addClass('right-sidebar-collapsed');
+ $layoutPage.removeClass('right-sidebar-expanded').addClass('right-sidebar-collapsed');
+ } else {
+ $layoutPage.removeClass('right-sidebar-expanded right-sidebar-collapsed');
+ }
+}
- return true;
- });
+// prevent default action for disabled buttons
+$('.btn').click(function clickDisabledButtonCallback(e) {
+ if ($(this).hasClass('disabled')) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ return false;
+ }
- 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) {
- const $buttons = $('[type="submit"], .js-disable-on-submit', this).not('.js-no-auto-disable');
- switch (e.type) {
- case 'ajax:beforeSend':
- case 'submit':
- return $buttons.disable();
- default:
- return $buttons.enable();
- }
- });
+ return true;
+});
- $('.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);
- });
+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) {
+ const $buttons = $('[type="submit"], .js-disable-on-submit', this).not('.js-no-auto-disable');
+ switch (e.type) {
+ case 'ajax:beforeSend':
+ case 'submit':
+ return $buttons.disable();
+ default:
+ return $buttons.enable();
+ }
+});
- /**
- * Show suppressed commit diff
- *
- * TODO: Move to commit diff pages
- */
- $document.on('click', '.diff-content .js-show-suppressed-diff', function showDiffCallback() {
- const $container = $(this).parent();
- $container.next('table').show();
- $container.remove();
- });
+$('.navbar-toggler').on('click', () => {
+ document.body.classList.toggle('top-nav-responsive-open');
+});
- // 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');
+/**
+ * Show suppressed commit diff
+ *
+ * TODO: Move to commit diff pages
+ */
+$document.on('click', '.diff-content .js-show-suppressed-diff', function showDiffCallback() {
+ const $container = $(this).parent();
+ $container.next('table').show();
+ $container.remove();
+});
- e.preventDefault();
+// 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');
- $this.toggleClass('selected');
+ e.preventDefault();
- if ($this.hasClass('active')) {
- notesHolders.show().find('.hide, .content').show();
- } else {
- notesHolders.hide().find('.content').hide();
- }
+ $this.toggleClass('selected');
- $(document).trigger('toggle.comments');
- });
+ if ($this.hasClass('active')) {
+ notesHolders.show().find('.hide, .content').show();
+ } else {
+ notesHolders.hide().find('.content').hide();
+ }
- $('form.filter-form').on('submit', function filterFormSubmitCallback(event) {
- const link = document.createElement('a');
- link.href = this.action;
+ $(document).trigger('toggle.comments');
+});
- const action = `${this.action}${link.search === '' ? '?' : '&'}`;
+$('form.filter-form').on('submit', function filterFormSubmitCallback(event) {
+ const link = document.createElement('a');
+ link.href = this.action;
- event.preventDefault();
- // eslint-disable-next-line no-jquery/no-serialize
- visitUrl(`${action}${$(this).serialize()}`);
- });
+ const action = `${this.action}${link.search === '' ? '?' : '&'}`;
- const flashContainer = document.querySelector('.flash-container');
+ event.preventDefault();
+ // eslint-disable-next-line no-jquery/no-serialize
+ visitUrl(`${action}${$(this).serialize()}`);
+});
- if (flashContainer && flashContainer.children.length) {
- flashContainer
- .querySelectorAll('.flash-alert, .flash-notice, .flash-success')
- .forEach((flashEl) => {
- removeFlashClickListener(flashEl);
- });
- }
+const flashContainer = document.querySelector('.flash-container');
- // initialize field errors
- $('.gl-show-field-errors').each((i, form) => new GlFieldErrors(form));
+if (flashContainer && flashContainer.children.length) {
+ flashContainer
+ .querySelectorAll('.flash-alert, .flash-notice, .flash-success')
+ .forEach((flashEl) => {
+ removeFlashClickListener(flashEl);
+ });
+}
- requestIdleCallback(deferredInitialisation);
-});
+// initialize field errors
+$('.gl-show-field-errors').each((i, form) => new GlFieldErrors(form));
+
+requestIdleCallback(deferredInitialisation);