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';
|
2017-09-22 04:39:47 -04:00
|
|
|
import svg4everybody from 'svg4everybody';
|
2017-03-01 18:02:01 -05:00
|
|
|
|
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
|
2018-02-23 04:00:19 -05: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
|
2017-06-26 23:43:32 -04:00
|
|
|
import loadAwardsHandler from './awards_handler';
|
2017-08-10 09:02:30 -04:00
|
|
|
import bp from './breakpoints';
|
2017-10-13 05:35:40 -04:00
|
|
|
import Flash, { removeFlashClickListener } from './flash';
|
2017-03-07 16:25:27 -05:00
|
|
|
import './gl_dropdown';
|
2017-10-30 14:59:16 -04:00
|
|
|
import initTodoToggle from './header';
|
2017-10-26 14:03:48 -04:00
|
|
|
import initImporterStatus from './importer_status';
|
2017-12-19 03:32:51 -05:00
|
|
|
import initLayoutNav from './layout_nav';
|
2018-01-10 23:16:27 -05:00
|
|
|
import './feature_highlight/feature_highlight_options';
|
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-03-07 16:25:27 -05:00
|
|
|
import './milestone_select';
|
2017-09-04 11:48:20 -04:00
|
|
|
import './projects_dropdown';
|
2017-08-16 08:13:34 -04:00
|
|
|
import initBreadcrumbs from './breadcrumb';
|
2018-02-01 22:28:50 -05:00
|
|
|
import initDispatcher from './dispatcher';
|
2017-08-03 16:31:53 -04:00
|
|
|
|
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
|
|
|
|
if (process.env.NODE_ENV !== 'production' && gon && gon.test_env) {
|
|
|
|
$.fx.off = true;
|
|
|
|
import(/* webpackMode: "eager" */ './test_utils/');
|
|
|
|
}
|
2017-02-23 16:40:36 -05:00
|
|
|
|
2017-09-22 04:39:47 -04:00
|
|
|
svg4everybody();
|
|
|
|
|
2017-12-19 05:12:32 -05:00
|
|
|
document.addEventListener('beforeunload', () => {
|
2017-03-11 02:30:44 -05:00
|
|
|
// Unbind scroll events
|
|
|
|
$(document).off('scroll');
|
|
|
|
// Close any open tooltips
|
2018-04-19 15:16:18 -04:00
|
|
|
$('.has-tooltip, [data-toggle="tooltip"]').tooltip('dispose');
|
2017-06-23 16:52:43 -04:00
|
|
|
// Close any open popover
|
2018-04-24 16:43:55 -04:00
|
|
|
$('[data-toggle="popover"]').popover('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
|
|
|
});
|
|
|
|
|
2018-02-21 00:58:50 -05:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2017-12-19 05:12:32 -05:00
|
|
|
const $body = $('body');
|
|
|
|
const $document = $(document);
|
|
|
|
const $window = $(window);
|
|
|
|
const $sidebarGutterToggle = $('.js-sidebar-toggle');
|
|
|
|
let bootstrapBreakpoint = bp.getBreakpointSize();
|
2016-10-24 17:31:01 -04:00
|
|
|
|
2017-08-16 08:13:34 -04:00
|
|
|
initBreadcrumbs();
|
2017-12-19 03:32:51 -05:00
|
|
|
initLayoutNav();
|
2017-10-26 14:03:48 -04:00
|
|
|
initImporterStatus();
|
2017-10-30 14:59:16 -04:00
|
|
|
initTodoToggle();
|
2017-11-01 08:32:15 -04:00
|
|
|
initLogoAnimation();
|
2017-08-16 08:13:34 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
// Set the default path for all cookies to GitLab's root directory
|
|
|
|
Cookies.defaults.path = gon.relative_url_root || '/';
|
2016-12-28 10:54:51 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
// `hashchange` is not triggered when link target is already in window.location
|
2017-12-19 05:12:32 -05:00
|
|
|
$body.on('click', 'a[href^="#"]', function clickHashLinkCallback() {
|
|
|
|
const href = this.getAttribute('href');
|
2017-12-07 07:30:53 -05:00
|
|
|
if (href.substr(1) === getLocationHash()) {
|
2017-09-06 12:14:34 -04:00
|
|
|
setTimeout(handleLocationHash, 1);
|
2017-03-11 02:30:44 -05:00
|
|
|
}
|
|
|
|
});
|
2016-11-06 19:16:39 -05:00
|
|
|
|
2017-04-19 15:10:16 -04:00
|
|
|
if (bootstrapBreakpoint === 'xs') {
|
2017-12-08 16:19:01 -05:00
|
|
|
const $rightSidebar = $('aside.right-sidebar, .layout-page');
|
2017-04-19 15:10:16 -04:00
|
|
|
|
2018-05-06 02:16:29 -04:00
|
|
|
$rightSidebar.removeClass('right-sidebar-expanded').addClass('right-sidebar-collapsed');
|
2017-04-19 15:10:16 -04:00
|
|
|
}
|
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
// prevent default action for disabled buttons
|
2017-12-19 05:12:32 -05:00
|
|
|
$('.btn').click(function clickDisabledButtonCallback(e) {
|
2017-03-11 02:30:44 -05:00
|
|
|
if ($(this).hasClass('disabled')) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopImmediatePropagation();
|
|
|
|
return false;
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2017-12-19 05:12:32 -05:00
|
|
|
|
|
|
|
return true;
|
2017-03-11 02:30:44 -05: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() {
|
2018-05-06 02:16:29 -04:00
|
|
|
$(this)
|
2018-05-08 11:49:30 -04:00
|
|
|
.tooltip('dispose')
|
2017-03-11 02:30:44 -05:00
|
|
|
.closest('li')
|
|
|
|
.fadeOut();
|
|
|
|
});
|
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() {
|
2018-05-06 02:16:29 -04:00
|
|
|
$(this)
|
|
|
|
.closest('tr')
|
|
|
|
.fadeOut();
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
|
|
|
// Initialize select2 selects
|
2017-03-11 02:30:44 -05:00
|
|
|
$('select.select2').select2({
|
|
|
|
width: 'resolve',
|
2017-12-19 05:12:32 -05:00
|
|
|
dropdownAutoWidth: true,
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
// Close select2 on escape
|
2017-12-19 05:12:32 -05:00
|
|
|
$('.js-select2').on('select2-close', () => {
|
|
|
|
setTimeout(() => {
|
|
|
|
$('.select2-container-active').removeClass('select2-container-active');
|
|
|
|
$(':focus').blur();
|
|
|
|
}, 1);
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
// Initialize tooltips
|
2018-04-20 10:44:56 -04:00
|
|
|
$body.tooltip({
|
|
|
|
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',
|
2017-12-19 05:12:32 -05:00
|
|
|
placement(tip, el) {
|
2017-03-11 02:30:44 -05:00
|
|
|
return $(el).data('placement') || 'bottom';
|
2017-12-19 05:12:32 -05:00
|
|
|
},
|
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
|
|
|
|
$body.popover({
|
2017-06-26 08:41:17 -04:00
|
|
|
selector: '[data-toggle="popover"]',
|
2017-09-05 03:26:40 -04:00
|
|
|
trigger: 'focus',
|
|
|
|
// set the viewport to the main content, excluding the navigation bar, so
|
|
|
|
// the navigation can't overlap the popover
|
2017-12-19 05:12:32 -05:00
|
|
|
viewport: '.layout-page',
|
2017-06-23 16:52:43 -04:00
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
// Form submitter
|
2017-12-19 05:12:32 -05:00
|
|
|
$('.trigger-submit').on('change', function triggerSubmitCallback() {
|
2018-05-06 02:16:29 -04:00
|
|
|
$(this)
|
|
|
|
.parents('form')
|
|
|
|
.submit();
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2017-12-07 06:09:17 -05:00
|
|
|
localTimeAgo($('abbr.timeago, .js-timeago'), true);
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
// Disable form buttons while a form is submitting
|
2017-12-19 05:12:32 -05:00
|
|
|
$body.on('ajax:complete, ajax:beforeSend, submit', 'form', function ajaxCompleteCallback(e) {
|
|
|
|
const $buttons = $('[type="submit"], .js-disable-on-submit', this);
|
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
|
|
|
|
|
|
|
$(document).ajaxError((e, xhrObj) => {
|
|
|
|
const ref = xhrObj.status;
|
|
|
|
|
|
|
|
if (ref === 401) {
|
|
|
|
Flash('You need to be logged in.');
|
2017-03-11 02:30:44 -05:00
|
|
|
} else if (ref === 404 || ref === 500) {
|
2017-12-19 05:12:32 -05:00
|
|
|
Flash('Something went wrong on our end.');
|
2017-03-11 02:30:44 -05:00
|
|
|
}
|
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
// Commit show suppressed diff
|
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
|
|
|
|
2018-04-10 14:10:52 -04:00
|
|
|
$('.navbar-toggler').on('click', () => {
|
2017-09-27 09:37:44 -04:00
|
|
|
$('.header-content').toggleClass('menu-expanded');
|
|
|
|
gl.lazyLoader.loadCheck();
|
|
|
|
});
|
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();
|
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
$this.toggleClass('active');
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
if ($this.hasClass('active')) {
|
2018-05-06 02:16:29 -04:00
|
|
|
notesHolders
|
|
|
|
.show()
|
|
|
|
.find('.hide, .content')
|
|
|
|
.show();
|
2017-03-11 02:30:44 -05:00
|
|
|
} else {
|
2018-05-06 02:16:29 -04: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
|
|
|
|
|
|
|
$document.on('breakpoint:change', (e, breakpoint) => {
|
2017-03-11 02:30:44 -05:00
|
|
|
if (breakpoint === 'sm' || breakpoint === 'xs') {
|
2017-12-19 05:12:32 -05:00
|
|
|
const $gutterIcon = $sidebarGutterToggle.find('i');
|
2017-03-11 02:30:44 -05:00
|
|
|
if ($gutterIcon.hasClass('fa-angle-double-right')) {
|
2017-12-19 05:12:32 -05:00
|
|
|
$sidebarGutterToggle.trigger('click');
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2017-03-11 02:30:44 -05:00
|
|
|
}
|
2016-07-12 18:52:36 -04:00
|
|
|
});
|
2017-12-19 05:12:32 -05:00
|
|
|
|
|
|
|
function fitSidebarForSize() {
|
|
|
|
const oldBootstrapBreakpoint = bootstrapBreakpoint;
|
2017-03-11 02:30:44 -05:00
|
|
|
bootstrapBreakpoint = bp.getBreakpointSize();
|
2017-12-19 05:12:32 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
if (bootstrapBreakpoint !== oldBootstrapBreakpoint) {
|
2017-12-19 05:12:32 -05:00
|
|
|
$document.trigger('breakpoint:change', [bootstrapBreakpoint]);
|
2017-03-11 02:30:44 -05:00
|
|
|
}
|
2017-12-19 05:12:32 -05:00
|
|
|
}
|
2017-03-11 02:30:44 -05:00
|
|
|
|
2017-12-19 05:12:32 -05:00
|
|
|
$window.on('resize.app', fitSidebarForSize);
|
|
|
|
|
|
|
|
loadAwardsHandler();
|
2017-03-28 10:56:08 -04:00
|
|
|
|
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();
|
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')
|
|
|
|
.forEach(flashEl => {
|
|
|
|
removeFlashClickListener(flashEl);
|
|
|
|
});
|
2017-10-13 05:35:40 -04:00
|
|
|
}
|
2018-02-01 22:28:50 -05:00
|
|
|
|
|
|
|
initDispatcher();
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|