2018-03-09 15:18:59 -05:00
|
|
|
/* global $ */
|
2021-02-15 16:08:59 -05:00
|
|
|
/* eslint-disable import/order */
|
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';
|
|
|
|
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-03-23 20:09:26 -04:00
|
|
|
import { handleLocationHash, addSelectOnFocusBehaviour } from './lib/utils/common_utils';
|
2017-12-19 05:12:32 -05:00
|
|
|
import { localTimeAgo } from './lib/utils/datetime_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';
|
2020-05-21 20:08:07 -04:00
|
|
|
import initFrequentItemDropdowns from './frequent_items';
|
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';
|
2018-09-07 10:32:28 -04:00
|
|
|
import initUsagePingConsent from './usage_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';
|
2017-08-03 16:31:53 -04:00
|
|
|
|
2019-07-04 06:18:51 -04:00
|
|
|
import 'ee_else_ce/main_ee';
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
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();
|
2018-09-07 10:32:28 -04:00
|
|
|
initUsagePingConsent();
|
2018-12-07 22:12:23 -05:00
|
|
|
initUserPopovers();
|
2020-01-28 13:08:35 -05:00
|
|
|
initBroadcastNotifications();
|
2020-05-21 20:08:07 -04:00
|
|
|
initFrequentItemDropdowns();
|
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
|
|
|
|
2020-09-11 23:09:29 -04:00
|
|
|
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 },
|
|
|
|
);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
$('.remove-row').on('ajax:success', function removeRowAjaxSuccessCallback() {
|
2020-10-01 08:10:14 -04:00
|
|
|
tooltips.dispose(this);
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
$(this).closest('li').addClass('gl-display-none!');
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
|
|
|
$('.js-remove-tr').on('ajax:before', function removeTRAjaxBeforeCallback() {
|
|
|
|
$(this).hide();
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
|
|
|
$('.js-remove-tr').on('ajax:success', function removeTRAjaxSuccessCallback() {
|
2020-12-23 07:10:26 -05:00
|
|
|
$(this).closest('tr').addClass('gl-display-none!');
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|
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
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
const $body = $('body');
|
|
|
|
const $document = $(document);
|
2020-06-18 20:09:12 -04:00
|
|
|
const bootstrapBreakpoint = bp.getBreakpointSize();
|
2019-01-08 06:25:02 -05:00
|
|
|
|
2020-05-07 02:09:38 -04:00
|
|
|
initUserTracking();
|
2019-01-08 06:25:02 -05:00
|
|
|
initLayoutNav();
|
2020-09-08 05:08:31 -04:00
|
|
|
initAlertHandler();
|
2019-01-08 06:25:02 -05:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-18 20:09:12 -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
|
|
|
|
*/
|
2020-02-27 01:09:20 -05:00
|
|
|
const isBoardsPage = /(projects|groups):boards:show/.test(document.body.dataset.page);
|
|
|
|
if (!isBoardsPage && (bootstrapBreakpoint === 'sm' || bootstrapBreakpoint === 'xs')) {
|
2020-02-17 10:09:01 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// prevent default action for disabled buttons
|
|
|
|
$('.btn').click(function clickDisabledButtonCallback(e) {
|
|
|
|
if ($(this).hasClass('disabled')) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopImmediatePropagation();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
localTimeAgo($('abbr.timeago, .js-timeago'), true);
|
|
|
|
|
2020-06-18 20:09:12 -04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2017-12-19 05:12:32 -05:00
|
|
|
$body.on('ajax:complete, ajax:beforeSend, submit', 'form', function ajaxCompleteCallback(e) {
|
2020-01-15 10:08:32 -05:00
|
|
|
const $buttons = $('[type="submit"], .js-disable-on-submit', this).not('.js-no-auto-disable');
|
2017-03-11 02:30:44 -05:00
|
|
|
switch (e.type) {
|
|
|
|
case 'ajax:beforeSend':
|
|
|
|
case 'submit':
|
2017-12-19 05:12:32 -05:00
|
|
|
return $buttons.disable();
|
2017-03-11 02:30:44 -05:00
|
|
|
default:
|
2017-12-19 05:12:32 -05:00
|
|
|
return $buttons.enable();
|
2017-03-11 02:30:44 -05:00
|
|
|
}
|
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2019-01-08 06:25:02 -05:00
|
|
|
$('.navbar-toggler').on('click', () => {
|
|
|
|
$('.header-content').toggleClass('menu-expanded');
|
|
|
|
});
|
|
|
|
|
2020-06-18 20:09:12 -04:00
|
|
|
/**
|
|
|
|
* Show suppressed commit diff
|
|
|
|
*
|
|
|
|
* TODO: Move to commit diff pages
|
|
|
|
*/
|
2017-12-19 05:12:32 -05:00
|
|
|
$document.on('click', '.diff-content .js-show-suppressed-diff', function showDiffCallback() {
|
|
|
|
const $container = $(this).parent();
|
|
|
|
$container.next('table').show();
|
|
|
|
$container.remove();
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
// Show/hide comments on diff
|
2017-12-19 05:12:32 -05:00
|
|
|
$body.on('click', '.js-toggle-diff-comments', function toggleDiffCommentsCallback(e) {
|
|
|
|
const $this = $(this);
|
|
|
|
const notesHolders = $this.closest('.diff-file').find('.notes_holder');
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
2021-03-15 14:09:05 -04:00
|
|
|
$this.toggleClass('selected');
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
if ($this.hasClass('active')) {
|
2020-12-23 07:10:26 -05:00
|
|
|
notesHolders.show().find('.hide, .content').show();
|
2017-03-11 02:30:44 -05:00
|
|
|
} else {
|
2020-12-23 07:10:26 -05:00
|
|
|
notesHolders.hide().find('.content').hide();
|
2017-03-11 02:30:44 -05:00
|
|
|
}
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
$(document).trigger('toggle.comments');
|
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
|
|
|
$('form.filter-form').on('submit', function filterFormSubmitCallback(event) {
|
2017-07-28 04:00:09 -04:00
|
|
|
const link = document.createElement('a');
|
|
|
|
link.href = this.action;
|
|
|
|
|
|
|
|
const action = `${this.action}${link.search === '' ? '?' : '&'}`;
|
|
|
|
|
2017-07-25 11:27:51 -04:00
|
|
|
event.preventDefault();
|
2019-09-19 17:06:29 -04:00
|
|
|
// eslint-disable-next-line no-jquery/no-serialize
|
2017-12-07 07:30:53 -05:00
|
|
|
visitUrl(`${action}${$(this).serialize()}`);
|
2017-07-25 11:27:51 -04:00
|
|
|
});
|
2017-10-13 05:35:40 -04:00
|
|
|
|
|
|
|
const flashContainer = document.querySelector('.flash-container');
|
|
|
|
|
|
|
|
if (flashContainer && flashContainer.children.length) {
|
2018-05-06 02:16:29 -04:00
|
|
|
flashContainer
|
|
|
|
.querySelectorAll('.flash-alert, .flash-notice, .flash-success')
|
2020-12-23 16:10:24 -05:00
|
|
|
.forEach((flashEl) => {
|
2018-05-06 02:16:29 -04:00
|
|
|
removeFlashClickListener(flashEl);
|
|
|
|
});
|
2017-10-13 05:35:40 -04:00
|
|
|
}
|
2018-02-01 22:28:50 -05:00
|
|
|
|
2018-09-13 17:01:12 -04:00
|
|
|
// initialize field errors
|
|
|
|
$('.gl-show-field-errors').each((i, form) => new GlFieldErrors(form));
|
2019-01-08 06:25:02 -05:00
|
|
|
|
|
|
|
requestIdleCallback(deferredInitialisation);
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|