2018-03-09 15:18:59 -05:00
|
|
|
/* global $ */
|
2016-12-14 00:26:26 -05:00
|
|
|
|
2017-03-01 18:02:01 -05:00
|
|
|
import jQuery from 'jquery';
|
|
|
|
import Cookies from 'js-cookie';
|
|
|
|
|
2018-05-06 02:19:04 -04:00
|
|
|
// bootstrap webpack, common libs, polyfills, and behaviors
|
|
|
|
import './webpack';
|
|
|
|
import './commons';
|
|
|
|
import './behaviors';
|
2017-02-23 16:40:36 -05:00
|
|
|
|
|
|
|
// lib/utils
|
2020-08-17 17:09:56 -04:00
|
|
|
import applyGitLabUIConfig from '@gitlab/ui/dist/config';
|
|
|
|
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
|
2020-09-21 11:09:44 -04:00
|
|
|
import { initRails } from '~/lib/utils/rails_ujs';
|
2021-02-01 10:08:56 -05:00
|
|
|
import * as popovers from '~/popovers';
|
2021-02-14 13:09:20 -05:00
|
|
|
import * as tooltips from '~/tooltips';
|
2021-09-20 23:11:06 -04:00
|
|
|
import { initHeaderSearchApp } from '~/header_search';
|
2021-02-14 13:09:20 -05:00
|
|
|
import initAlertHandler from './alert_handler';
|
2021-03-23 20:09:26 -04:00
|
|
|
import { removeFlashClickListener } from './flash';
|
2021-02-14 13:09:20 -05:00
|
|
|
import initTodoToggle from './header';
|
|
|
|
import initLayoutNav from './layout_nav';
|
2021-09-14 14:12:06 -04:00
|
|
|
import { logHelloDeferred } from './lib/logger/hello_deferred';
|
2021-03-23 20:09:26 -04:00
|
|
|
import { handleLocationHash, addSelectOnFocusBehaviour } from './lib/utils/common_utils';
|
2021-06-15 05:10:21 -04:00
|
|
|
import { localTimeAgo } from './lib/utils/datetime/timeago_utility';
|
2017-12-07 07:30:53 -05:00
|
|
|
import { getLocationHash, visitUrl } from './lib/utils/url_utility';
|
2017-02-23 16:40:36 -05:00
|
|
|
|
|
|
|
// everything else
|
2021-02-15 01:09:22 -05:00
|
|
|
import initFeatureHighlight from './feature_highlight';
|
2017-07-24 13:36:52 -04:00
|
|
|
import LazyLoader from './lazy_loader';
|
2017-11-01 08:32:15 -04:00
|
|
|
import initLogoAnimation from './logo';
|
2017-08-16 08:13:34 -04:00
|
|
|
import initBreadcrumbs from './breadcrumb';
|
2021-02-14 13:09:20 -05:00
|
|
|
import initPersistentUserCallouts from './persistent_user_callouts';
|
|
|
|
import { initUserTracking, initDefaultTrackers } from './tracking';
|
2021-06-29 08:08:48 -04:00
|
|
|
import initServicePingConsent from './service_ping_consent';
|
2018-09-13 17:01:12 -04:00
|
|
|
import GlFieldErrors from './gl_field_errors';
|
2018-12-07 22:12:23 -05:00
|
|
|
import initUserPopovers from './user_popovers';
|
2020-01-28 13:08:35 -05:00
|
|
|
import initBroadcastNotifications from './broadcast_notification';
|
2021-05-17 14:10:42 -04:00
|
|
|
import { initTopNav } from './nav';
|
2017-08-03 16:31:53 -04:00
|
|
|
|
2019-07-04 06:18:51 -04:00
|
|
|
import 'ee_else_ce/main_ee';
|
2021-08-30 05:09:12 -04:00
|
|
|
import 'jh_else_ce/main_jh';
|
2019-07-04 06:18:51 -04:00
|
|
|
|
2021-09-14 14:12:06 -04:00
|
|
|
logHelloDeferred();
|
|
|
|
|
2020-06-23 14:09:28 -04:00
|
|
|
applyGitLabUIConfig();
|
|
|
|
|
2018-05-06 02:19:04 -04:00
|
|
|
// expose jQuery as global (TODO: remove these)
|
|
|
|
window.jQuery = jQuery;
|
|
|
|
window.$ = jQuery;
|
|
|
|
|
2021-07-14 20:10:03 -04:00
|
|
|
// ensure that window.gl is set up
|
|
|
|
window.gl = window.gl || {};
|
|
|
|
|
2018-02-28 16:22:15 -05:00
|
|
|
// inject test utilities if necessary
|
2020-06-18 20:09:12 -04:00
|
|
|
if (process.env.NODE_ENV !== 'production' && gon?.test_env) {
|
2021-02-05 07:09:31 -05:00
|
|
|
import(/* webpackMode: "eager" */ './test_utils/');
|
2018-02-28 16:22:15 -05:00
|
|
|
}
|
2017-02-23 16:40:36 -05:00
|
|
|
|
2017-12-19 05:12:32 -05:00
|
|
|
document.addEventListener('beforeunload', () => {
|
2017-03-11 02:30:44 -05:00
|
|
|
// Unbind scroll events
|
2020-12-08 16:10:06 -05:00
|
|
|
// eslint-disable-next-line @gitlab/no-global-event-off
|
2017-03-11 02:30:44 -05:00
|
|
|
$(document).off('scroll');
|
|
|
|
// Close any open tooltips
|
2020-10-01 08:10:14 -04:00
|
|
|
tooltips.dispose(document.querySelectorAll('.has-tooltip, [data-toggle="tooltip"]'));
|
2017-06-23 16:52:43 -04:00
|
|
|
// Close any open popover
|
2020-10-27 11:08:39 -04:00
|
|
|
popovers.dispose();
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-09-06 12:14:34 -04:00
|
|
|
window.addEventListener('hashchange', handleLocationHash);
|
2018-05-06 02:16:29 -04:00
|
|
|
window.addEventListener(
|
|
|
|
'load',
|
|
|
|
function onLoad() {
|
|
|
|
window.removeEventListener('load', onLoad, false);
|
|
|
|
handleLocationHash();
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
);
|
2016-10-24 17:31:01 -04:00
|
|
|
|
2017-07-24 13:36:52 -04:00
|
|
|
gl.lazyLoader = new LazyLoader({
|
|
|
|
scrollContainer: window,
|
2017-12-19 05:12:32 -05:00
|
|
|
observerNode: '#content-body',
|
2017-07-24 13:36:52 -04:00
|
|
|
});
|
|
|
|
|
2020-09-30 02:09:47 -04:00
|
|
|
initRails();
|
|
|
|
|
2019-01-08 06:25:02 -05:00
|
|
|
// Put all initialisations here that can also wait after everything is rendered and ready
|
|
|
|
function deferredInitialisation() {
|
2017-12-19 05:12:32 -05:00
|
|
|
const $body = $('body');
|
2016-10-24 17:31:01 -04:00
|
|
|
|
2021-05-17 14:10:42 -04:00
|
|
|
initTopNav();
|
2017-08-16 08:13:34 -04:00
|
|
|
initBreadcrumbs();
|
2017-10-30 14:59:16 -04:00
|
|
|
initTodoToggle();
|
2017-11-01 08:32:15 -04:00
|
|
|
initLogoAnimation();
|
2021-06-29 08:08:48 -04:00
|
|
|
initServicePingConsent();
|
2018-12-07 22:12:23 -05:00
|
|
|
initUserPopovers();
|
2020-01-28 13:08:35 -05:00
|
|
|
initBroadcastNotifications();
|
2020-06-01 20:08:07 -04:00
|
|
|
initPersistentUserCallouts();
|
2020-09-04 08:08:27 -04:00
|
|
|
initDefaultTrackers();
|
2021-02-15 01:09:22 -05:00
|
|
|
initFeatureHighlight();
|
2020-05-18 08:08:08 -04:00
|
|
|
|
2021-09-06 21:02:14 -04:00
|
|
|
if (gon.features?.newHeaderSearch) {
|
|
|
|
initHeaderSearchApp();
|
|
|
|
} else {
|
|
|
|
const search = document.querySelector('#search');
|
|
|
|
if (search) {
|
|
|
|
search.addEventListener(
|
|
|
|
'focus',
|
|
|
|
() => {
|
|
|
|
import(/* webpackChunkName: 'globalSearch' */ './search_autocomplete')
|
|
|
|
.then(({ default: initSearchAutocomplete }) => {
|
|
|
|
const searchDropdown = initSearchAutocomplete();
|
|
|
|
searchDropdown.onSearchInputFocus();
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
},
|
|
|
|
{ once: true },
|
|
|
|
);
|
|
|
|
}
|
2020-09-11 23:09:29 -04:00
|
|
|
}
|
2018-09-13 17:59:09 -04:00
|
|
|
|
2018-02-23 04:00:19 -05:00
|
|
|
addSelectOnFocusBehaviour('.js-select-on-focus');
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2019-06-28 15:27:47 -04:00
|
|
|
const glTooltipDelay = localStorage.getItem('gl-tooltip-delay');
|
|
|
|
const delay = glTooltipDelay ? JSON.parse(glTooltipDelay) : 0;
|
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
// Initialize tooltips
|
2020-10-01 08:10:14 -04:00
|
|
|
tooltips.initTooltips({
|
2018-04-20 10:44:56 -04:00
|
|
|
selector: '.has-tooltip, [data-toggle="tooltip"]',
|
2018-05-08 12:16:35 -04:00
|
|
|
trigger: 'hover',
|
2018-06-08 00:27:36 -04:00
|
|
|
boundary: 'viewport',
|
2019-06-28 15:27:47 -04:00
|
|
|
delay,
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2017-06-23 16:52:43 -04:00
|
|
|
// Initialize popovers
|
2020-10-27 11:08:39 -04:00
|
|
|
popovers.initPopovers();
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2020-08-17 11:10:09 -04:00
|
|
|
// Adding a helper class to activate animations only after all is rendered
|
|
|
|
setTimeout(() => $body.addClass('page-initialised'), 1000);
|
2019-01-08 06:25:02 -05:00
|
|
|
}
|
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2019-01-08 06:25:02 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
/**
|
|
|
|
* 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');
|
2019-01-08 06:25:02 -05:00
|
|
|
}
|
2021-07-27 08:10:54 -04:00
|
|
|
}
|
2019-01-08 06:25:02 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
// prevent default action for disabled buttons
|
|
|
|
$('.btn').click(function clickDisabledButtonCallback(e) {
|
|
|
|
if ($(this).hasClass('disabled')) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopImmediatePropagation();
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-08 06:25:02 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
return true;
|
|
|
|
});
|
2019-01-08 06:25:02 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
$('.navbar-toggler').on('click', () => {
|
2021-07-28 17:08:53 -04:00
|
|
|
document.body.classList.toggle('top-nav-responsive-open');
|
2021-07-27 08:10:54 -04:00
|
|
|
});
|
2019-01-08 06:25:02 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
// 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');
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
e.preventDefault();
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
$this.toggleClass('selected');
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
if ($this.hasClass('active')) {
|
|
|
|
notesHolders.show().find('.hide, .content').show();
|
|
|
|
} else {
|
|
|
|
notesHolders.hide().find('.content').hide();
|
|
|
|
}
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
$(document).trigger('toggle.comments');
|
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
$('form.filter-form').on('submit', function filterFormSubmitCallback(event) {
|
|
|
|
const link = document.createElement('a');
|
|
|
|
link.href = this.action;
|
2017-07-28 04:00:09 -04:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
const action = `${this.action}${link.search === '' ? '?' : '&'}`;
|
2017-07-28 04:00:09 -04:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
event.preventDefault();
|
|
|
|
// eslint-disable-next-line no-jquery/no-serialize
|
|
|
|
visitUrl(`${action}${$(this).serialize()}`);
|
|
|
|
});
|
2017-10-13 05:35:40 -04:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
const flashContainer = document.querySelector('.flash-container');
|
2017-10-13 05:35:40 -04:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
if (flashContainer && flashContainer.children.length) {
|
|
|
|
flashContainer
|
|
|
|
.querySelectorAll('.flash-alert, .flash-notice, .flash-success')
|
|
|
|
.forEach((flashEl) => {
|
|
|
|
removeFlashClickListener(flashEl);
|
|
|
|
});
|
|
|
|
}
|
2018-02-01 22:28:50 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
// initialize field errors
|
|
|
|
$('.gl-show-field-errors').each((i, form) => new GlFieldErrors(form));
|
2019-01-08 06:25:02 -05:00
|
|
|
|
2021-07-27 08:10:54 -04:00
|
|
|
requestIdleCallback(deferredInitialisation);
|