2017-03-07 16:25:27 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, quotes, consistent-return, prefer-arrow-callback, comma-dangle, object-shorthand, no-new, max-len, no-multi-spaces, import/newline-after-import, import/first */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global Flash */
|
|
|
|
/* global ConfirmDangerModal */
|
|
|
|
/* global Aside */
|
|
|
|
|
2017-03-01 18:02:01 -05:00
|
|
|
import jQuery from 'jquery';
|
|
|
|
import _ from 'underscore';
|
|
|
|
import Cookies from 'js-cookie';
|
|
|
|
import Dropzone from 'dropzone';
|
|
|
|
import Sortable from 'vendor/Sortable';
|
|
|
|
|
|
|
|
// libraries with import side-effects
|
2017-03-07 16:25:27 -05:00
|
|
|
import 'mousetrap';
|
|
|
|
import 'mousetrap/plugins/pause/mousetrap-pause';
|
|
|
|
import 'vendor/fuzzaldrin-plus';
|
2017-03-01 18:02:01 -05:00
|
|
|
|
|
|
|
// expose common libraries as globals (TODO: remove these)
|
|
|
|
window.jQuery = jQuery;
|
|
|
|
window.$ = jQuery;
|
|
|
|
window._ = _;
|
|
|
|
window.Dropzone = Dropzone;
|
|
|
|
window.Sortable = Sortable;
|
|
|
|
|
|
|
|
// shortcuts
|
2017-03-07 16:25:27 -05:00
|
|
|
import './shortcuts';
|
|
|
|
import './shortcuts_blob';
|
|
|
|
import './shortcuts_dashboard_navigation';
|
|
|
|
import './shortcuts_navigation';
|
|
|
|
import './shortcuts_find_file';
|
|
|
|
import './shortcuts_issuable';
|
|
|
|
import './shortcuts_network';
|
2017-02-23 16:40:36 -05:00
|
|
|
|
|
|
|
// templates
|
2017-03-07 16:25:27 -05:00
|
|
|
import './templates/issuable_template_selector';
|
|
|
|
import './templates/issuable_template_selectors';
|
2017-02-23 16:40:36 -05:00
|
|
|
|
|
|
|
// commit
|
2017-03-07 16:25:27 -05:00
|
|
|
import './commit/file';
|
|
|
|
import './commit/image_file';
|
2017-02-23 16:40:36 -05:00
|
|
|
|
|
|
|
// lib/utils
|
2017-03-07 16:25:27 -05:00
|
|
|
import './lib/utils/animate';
|
|
|
|
import './lib/utils/bootstrap_linked_tabs';
|
|
|
|
import './lib/utils/common_utils';
|
|
|
|
import './lib/utils/datetime_utility';
|
|
|
|
import './lib/utils/pretty_time';
|
|
|
|
import './lib/utils/text_utility';
|
|
|
|
import './lib/utils/url_utility';
|
2017-02-23 16:40:36 -05:00
|
|
|
|
2017-08-03 16:31:53 -04:00
|
|
|
// behaviors
|
|
|
|
import './behaviors/';
|
|
|
|
|
2017-02-23 16:40:36 -05:00
|
|
|
// u2f
|
2017-03-07 16:25:27 -05:00
|
|
|
import './u2f/authenticate';
|
|
|
|
import './u2f/error';
|
|
|
|
import './u2f/register';
|
|
|
|
import './u2f/util';
|
2017-02-23 16:40:36 -05:00
|
|
|
|
|
|
|
// everything else
|
2017-03-07 16:25:27 -05:00
|
|
|
import './abuse_reports';
|
|
|
|
import './activities';
|
|
|
|
import './admin';
|
|
|
|
import './ajax_loading_spinner';
|
|
|
|
import './api';
|
|
|
|
import './aside';
|
|
|
|
import './autosave';
|
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-03-07 16:25:27 -05:00
|
|
|
import './broadcast_message';
|
|
|
|
import './build';
|
|
|
|
import './build_artifacts';
|
|
|
|
import './build_variables';
|
|
|
|
import './ci_lint_editor';
|
|
|
|
import './commit';
|
|
|
|
import './commits';
|
|
|
|
import './compare';
|
|
|
|
import './compare_autocomplete';
|
|
|
|
import './confirm_danger_modal';
|
|
|
|
import './copy_as_gfm';
|
|
|
|
import './copy_to_clipboard';
|
|
|
|
import './create_label';
|
|
|
|
import './diff';
|
|
|
|
import './dropzone_input';
|
|
|
|
import './due_date_select';
|
|
|
|
import './files_comment_button';
|
|
|
|
import './flash';
|
|
|
|
import './gl_dropdown';
|
|
|
|
import './gl_field_error';
|
|
|
|
import './gl_field_errors';
|
|
|
|
import './gl_form';
|
|
|
|
import './group_avatar';
|
|
|
|
import './group_label_subscription';
|
|
|
|
import './groups_select';
|
|
|
|
import './header';
|
|
|
|
import './importer_status';
|
2017-05-15 18:12:43 -04:00
|
|
|
import './issuable_index';
|
2017-03-07 16:25:27 -05:00
|
|
|
import './issuable_context';
|
|
|
|
import './issuable_form';
|
|
|
|
import './issue';
|
|
|
|
import './issue_status_select';
|
|
|
|
import './label_manager';
|
|
|
|
import './labels';
|
|
|
|
import './labels_select';
|
|
|
|
import './layout_nav';
|
2017-07-24 13:36:52 -04:00
|
|
|
import LazyLoader from './lazy_loader';
|
2017-03-07 16:25:27 -05:00
|
|
|
import './line_highlighter';
|
|
|
|
import './logo';
|
|
|
|
import './member_expiration_date';
|
|
|
|
import './members';
|
|
|
|
import './merge_request';
|
|
|
|
import './merge_request_tabs';
|
|
|
|
import './milestone';
|
|
|
|
import './milestone_select';
|
|
|
|
import './mini_pipeline_graph_dropdown';
|
|
|
|
import './namespace_select';
|
|
|
|
import './new_branch_form';
|
|
|
|
import './new_commit_form';
|
|
|
|
import './notes';
|
|
|
|
import './notifications_dropdown';
|
|
|
|
import './notifications_form';
|
|
|
|
import './pager';
|
|
|
|
import './pipelines';
|
|
|
|
import './preview_markdown';
|
|
|
|
import './project';
|
|
|
|
import './project_avatar';
|
|
|
|
import './project_find_file';
|
|
|
|
import './project_fork';
|
|
|
|
import './project_import';
|
|
|
|
import './project_label_subscription';
|
|
|
|
import './project_new';
|
|
|
|
import './project_select';
|
|
|
|
import './project_show';
|
|
|
|
import './project_variables';
|
|
|
|
import './projects_list';
|
2017-08-08 09:25:00 -04:00
|
|
|
import './syntax_highlight';
|
2017-03-07 16:25:27 -05:00
|
|
|
import './render_math';
|
2017-08-08 09:25:00 -04:00
|
|
|
import './render_gfm';
|
2017-03-07 16:25:27 -05:00
|
|
|
import './right_sidebar';
|
|
|
|
import './search';
|
|
|
|
import './search_autocomplete';
|
|
|
|
import './smart_interval';
|
|
|
|
import './star';
|
|
|
|
import './subscription';
|
|
|
|
import './subscription_select';
|
2017-04-04 13:47:12 -04:00
|
|
|
|
2017-08-03 16:31:53 -04:00
|
|
|
import './dispatcher';
|
|
|
|
|
2017-05-18 16:11:20 -04:00
|
|
|
// eslint-disable-next-line global-require, import/no-commonjs
|
2017-04-04 13:47:12 -04:00
|
|
|
if (process.env.NODE_ENV !== 'production') require('./test_utils/');
|
2017-02-23 16:40:36 -05:00
|
|
|
|
2017-08-03 16:31:53 -04:00
|
|
|
Dropzone.autoDiscover = false;
|
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
document.addEventListener('beforeunload', function () {
|
|
|
|
// Unbind scroll events
|
|
|
|
$(document).off('scroll');
|
|
|
|
// Close any open tooltips
|
|
|
|
$('.has-tooltip, [data-toggle="tooltip"]').tooltip('destroy');
|
2017-06-23 16:52:43 -04:00
|
|
|
// Close any open popover
|
|
|
|
$('[data-toggle="popover"]').popover('destroy');
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
window.addEventListener('hashchange', gl.utils.handleLocationHash);
|
|
|
|
window.addEventListener('load', function onLoad() {
|
|
|
|
window.removeEventListener('load', onLoad, false);
|
|
|
|
gl.utils.handleLocationHash();
|
|
|
|
}, false);
|
2016-10-24 17:31:01 -04:00
|
|
|
|
2017-07-24 13:36:52 -04:00
|
|
|
gl.lazyLoader = new LazyLoader({
|
|
|
|
scrollContainer: window,
|
|
|
|
observerNode: '#content-body'
|
|
|
|
});
|
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
$(function () {
|
|
|
|
var $body = $('body');
|
|
|
|
var $document = $(document);
|
|
|
|
var $window = $(window);
|
|
|
|
var $sidebarGutterToggle = $('.js-sidebar-toggle');
|
|
|
|
var $flash = $('.flash-container');
|
|
|
|
var bootstrapBreakpoint = bp.getBreakpointSize();
|
|
|
|
var fitSidebarForSize;
|
2016-10-24 17:31:01 -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
|
|
|
|
$body.on('click', 'a[href^="#"]', function() {
|
|
|
|
var href = this.getAttribute('href');
|
|
|
|
if (href.substr(1) === gl.utils.getLocationHash()) {
|
|
|
|
setTimeout(gl.utils.handleLocationHash, 1);
|
|
|
|
}
|
|
|
|
});
|
2016-11-06 19:16:39 -05:00
|
|
|
|
2017-04-19 15:10:16 -04:00
|
|
|
if (bootstrapBreakpoint === 'xs') {
|
|
|
|
const $rightSidebar = $('aside.right-sidebar, .page-with-sidebar');
|
|
|
|
|
|
|
|
$rightSidebar
|
|
|
|
.removeClass('right-sidebar-expanded')
|
|
|
|
.addClass('right-sidebar-collapsed');
|
|
|
|
}
|
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
// prevent default action for disabled buttons
|
|
|
|
$('.btn').click(function(e) {
|
|
|
|
if ($(this).hasClass('disabled')) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopImmediatePropagation();
|
|
|
|
return false;
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
$('.js-select-on-focus').on('focusin', function () {
|
|
|
|
return $(this).select().one('mouseup', function (e) {
|
2016-07-24 16:45:11 -04:00
|
|
|
return e.preventDefault();
|
|
|
|
});
|
2017-03-11 02:30:44 -05:00
|
|
|
// Click a .js-select-on-focus field, select the contents
|
|
|
|
// Prevent a mouseup event from deselecting the input
|
|
|
|
});
|
|
|
|
$('.remove-row').bind('ajax:success', function () {
|
|
|
|
$(this).tooltip('destroy')
|
|
|
|
.closest('li')
|
|
|
|
.fadeOut();
|
|
|
|
});
|
|
|
|
$('.js-remove-tr').bind('ajax:before', function () {
|
|
|
|
return $(this).hide();
|
|
|
|
});
|
|
|
|
$('.js-remove-tr').bind('ajax:success', function () {
|
|
|
|
return $(this).closest('tr').fadeOut();
|
|
|
|
});
|
|
|
|
$('select.select2').select2({
|
|
|
|
width: 'resolve',
|
|
|
|
// Initialize select2 selects
|
|
|
|
dropdownAutoWidth: true
|
|
|
|
});
|
|
|
|
$('.js-select2').bind('select2-close', function () {
|
|
|
|
return setTimeout((function () {
|
|
|
|
$('.select2-container-active').removeClass('select2-container-active');
|
|
|
|
return $(':focus').blur();
|
|
|
|
}), 1);
|
|
|
|
// Close select2 on escape
|
|
|
|
});
|
|
|
|
// Initialize tooltips
|
|
|
|
$.fn.tooltip.Constructor.DEFAULTS.trigger = 'hover';
|
|
|
|
$body.tooltip({
|
|
|
|
selector: '.has-tooltip, [data-toggle="tooltip"]',
|
|
|
|
placement: function (tip, el) {
|
|
|
|
return $(el).data('placement') || 'bottom';
|
|
|
|
}
|
|
|
|
});
|
2017-06-23 16:52:43 -04:00
|
|
|
// Initialize popovers
|
|
|
|
$body.popover({
|
2017-06-26 08:41:17 -04:00
|
|
|
selector: '[data-toggle="popover"]',
|
|
|
|
trigger: 'focus'
|
2017-06-23 16:52:43 -04:00
|
|
|
});
|
2017-03-11 02:30:44 -05:00
|
|
|
$('.trigger-submit').on('change', function () {
|
|
|
|
return $(this).parents('form').submit();
|
|
|
|
// Form submitter
|
|
|
|
});
|
|
|
|
gl.utils.localTimeAgo($('abbr.timeago, .js-timeago'), true);
|
|
|
|
// Flash
|
|
|
|
if ($flash.length > 0) {
|
|
|
|
$flash.click(function () {
|
|
|
|
return $(this).fadeOut();
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-03-11 02:30:44 -05:00
|
|
|
$flash.show();
|
|
|
|
}
|
|
|
|
// Disable form buttons while a form is submitting
|
|
|
|
$body.on('ajax:complete, ajax:beforeSend, submit', 'form', function (e) {
|
|
|
|
var buttons;
|
2017-04-06 08:04:57 -04:00
|
|
|
buttons = $('[type="submit"], .js-disable-on-submit', this);
|
2017-03-11 02:30:44 -05:00
|
|
|
switch (e.type) {
|
|
|
|
case 'ajax:beforeSend':
|
|
|
|
case 'submit':
|
|
|
|
return buttons.disable();
|
|
|
|
default:
|
|
|
|
return buttons.enable();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(document).ajaxError(function (e, xhrObj) {
|
|
|
|
var ref = xhrObj.status;
|
|
|
|
if (xhrObj.status === 401) {
|
|
|
|
return new Flash('You need to be logged in.', 'alert');
|
|
|
|
} else if (ref === 404 || ref === 500) {
|
|
|
|
return new Flash('Something went wrong on our end.', 'alert');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('.account-box').hover(function () {
|
|
|
|
// Show/Hide the profile menu when hovering the account box
|
|
|
|
return $(this).toggleClass('hover');
|
|
|
|
});
|
|
|
|
$document.on('click', '.diff-content .js-show-suppressed-diff', function () {
|
|
|
|
var $container;
|
|
|
|
$container = $(this).parent();
|
|
|
|
$container.next('table').show();
|
|
|
|
return $container.remove();
|
|
|
|
// Commit show suppressed diff
|
|
|
|
});
|
2017-07-17 01:05:22 -04:00
|
|
|
$('.navbar-toggle').on('click', () => $('.header-content').toggleClass('menu-expanded'));
|
2017-03-11 02:30:44 -05:00
|
|
|
// Show/hide comments on diff
|
|
|
|
$body.on('click', '.js-toggle-diff-comments', function (e) {
|
|
|
|
var $this = $(this);
|
|
|
|
var notesHolders = $this.closest('.diff-file').find('.notes_holder');
|
|
|
|
$this.toggleClass('active');
|
|
|
|
if ($this.hasClass('active')) {
|
|
|
|
notesHolders.show().find('.hide, .content').show();
|
|
|
|
} else {
|
|
|
|
notesHolders.hide().find('.content').hide();
|
|
|
|
}
|
|
|
|
$(document).trigger('toggle.comments');
|
|
|
|
return e.preventDefault();
|
|
|
|
});
|
|
|
|
$document.off('click', '.js-confirm-danger');
|
|
|
|
$document.on('click', '.js-confirm-danger', function (e) {
|
|
|
|
var btn = $(e.target);
|
|
|
|
var form = btn.closest('form');
|
|
|
|
var text = btn.data('confirm-danger-message');
|
|
|
|
e.preventDefault();
|
|
|
|
return new ConfirmDangerModal(form, text);
|
|
|
|
});
|
|
|
|
$('input[type="search"]').each(function () {
|
|
|
|
var $this = $(this);
|
|
|
|
$this.attr('value', $this.val());
|
|
|
|
});
|
|
|
|
$document.off('keyup', 'input[type="search"]').on('keyup', 'input[type="search"]', function () {
|
|
|
|
var $this;
|
|
|
|
$this = $(this);
|
|
|
|
return $this.attr('value', $this.val());
|
|
|
|
});
|
|
|
|
$document.off('breakpoint:change').on('breakpoint:change', function (e, breakpoint) {
|
|
|
|
var $gutterIcon;
|
|
|
|
if (breakpoint === 'sm' || breakpoint === 'xs') {
|
|
|
|
$gutterIcon = $sidebarGutterToggle.find('i');
|
|
|
|
if ($gutterIcon.hasClass('fa-angle-double-right')) {
|
|
|
|
return $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-03-11 02:30:44 -05:00
|
|
|
fitSidebarForSize = function () {
|
|
|
|
var oldBootstrapBreakpoint;
|
|
|
|
oldBootstrapBreakpoint = bootstrapBreakpoint;
|
|
|
|
bootstrapBreakpoint = bp.getBreakpointSize();
|
|
|
|
if (bootstrapBreakpoint !== oldBootstrapBreakpoint) {
|
|
|
|
return $document.trigger('breakpoint:change', [bootstrapBreakpoint]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$window.off('resize.app').on('resize.app', function () {
|
|
|
|
return fitSidebarForSize();
|
|
|
|
});
|
2017-06-26 23:43:32 -04:00
|
|
|
loadAwardsHandler();
|
2017-03-11 02:30:44 -05:00
|
|
|
new Aside();
|
|
|
|
|
2017-06-26 15:28:09 -04:00
|
|
|
gl.utils.renderTimeago();
|
2017-03-28 10:56:08 -04:00
|
|
|
|
|
|
|
$(document).trigger('init.scrolling-tabs');
|
2017-07-25 11:27:51 -04:00
|
|
|
|
|
|
|
$('form.filter-form').on('submit', function (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-07-28 04:00:09 -04:00
|
|
|
gl.utils.visitUrl(`${action}${$(this).serialize()}`);
|
2017-07-25 11:27:51 -04:00
|
|
|
});
|
2017-03-11 02:30:44 -05:00
|
|
|
});
|