Skip to content
Snippets Groups Projects
Unverified Commit ff0f74ac authored by Phil Hughes's avatar Phil Hughes
Browse files

Tidy up main JS file

parent be623ef3
No related branches found
No related tags found
No related merge requests found
Showing
with 115 additions and 120 deletions
Loading
Loading
@@ -7,7 +7,6 @@
"extends": "airbnb-base",
"globals": {
"__webpack_public_path__": true,
"_": false,
"gl": false,
"gon": false,
"localStorage": false
Loading
Loading
Loading
Loading
@@ -4,6 +4,8 @@ import { visitUrl } from '../lib/utils/url_utility';
import { HIDDEN_CLASS } from '../lib/utils/constants';
import csrf from '../lib/utils/csrf';
 
Dropzone.autoDiscover = false;
function toggleLoading($el, $icon, loading) {
if (loading) {
$el.disable();
Loading
Loading
/* eslint-disable comma-dangle, space-before-function-paren, one-var */
/* global Sortable */
import Sortable from 'vendor/Sortable';
import Vue from 'vue';
import AccessorUtilities from '../../lib/utils/accessor';
import boardList from './board_list';
Loading
Loading
/* global Sortable */
import Sortable from 'vendor/Sortable';
import boardNewIssue from './board_new_issue';
import boardCard from './board_card.vue';
import eventHub from '../eventhub';
Loading
Loading
import _ from 'underscore';
export default function initBroadcastMessagesForm() {
$('input#broadcast_message_color').on('input', function onMessageColorInput() {
const previewColor = $(this).val();
Loading
Loading
/* eslint-disable no-new */
import _ from 'underscore';
import Flash from './flash';
import DropLab from './droplab/drop_lab';
import ISetter from './droplab/plugins/input_setter';
Loading
Loading
Loading
Loading
@@ -3,6 +3,8 @@ import _ from 'underscore';
import './preview_markdown';
import csrf from './lib/utils/csrf';
 
Dropzone.autoDiscover = false;
export default function dropzoneInput(form) {
const divHover = '<div class="div-dropzone-hover"></div>';
const iconPaperclip = '<i class="fa fa-paperclip div-dropzone-icon"></i>';
Loading
Loading
/**
* Common code between environmets app and folder view
*/
import _ from 'underscore';
import Visibility from 'visibilityjs';
import Poll from '../../lib/utils/poll';
import {
Loading
Loading
import _ from 'underscore';
import DropLab from '~/droplab/drop_lab';
import FilteredSearchContainer from './container';
 
Loading
Loading
import _ from 'underscore';
import { visitUrl } from '../lib/utils/url_utility';
import Flash from '../flash';
import FilteredSearchContainer from './container';
Loading
Loading
import _ from 'underscore';
import AjaxCache from '../lib/utils/ajax_cache';
import Flash from '../flash';
import FilteredSearchContainer from './container';
Loading
Loading
import _ from 'underscore';
import DecorationsController from './decorations/controller';
import DirtyDiffController from './diff/controller';
import Disposable from './common/disposable';
Loading
Loading
import _ from 'underscore';
export const dataStructure = () => ({
id: '',
key: '',
Loading
Loading
/* eslint-disable comma-dangle, class-methods-use-this, no-underscore-dangle, no-param-reassign, no-unused-vars, consistent-return, func-names, space-before-function-paren, max-len */
/* global Sortable */
import Sortable from 'vendor/Sortable';
 
import Flash from './flash';
 
Loading
Loading
/* 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 */
/* eslint-disable import/first */
/* global ConfirmDangerModal */
 
import jQuery from 'jquery';
import _ from 'underscore';
import Cookies from 'js-cookie';
import Dropzone from 'dropzone';
import Sortable from 'vendor/Sortable';
import svg4everybody from 'svg4everybody';
 
// libraries with import side-effects
import 'mousetrap';
import 'mousetrap/plugins/pause/mousetrap-pause';
// expose common libraries as globals (TODO: remove these)
window.jQuery = jQuery;
window.$ = jQuery;
window._ = _;
window.Dropzone = Dropzone;
window.Sortable = Sortable;
// templates
import './templates/issuable_template_selector';
import './templates/issuable_template_selectors';
import './commit/image_file';
 
// lib/utils
import { handleLocationHash } from './lib/utils/common_utils';
import { localTimeAgo, renderTimeago } from './lib/utils/datetime_utility';
import { localTimeAgo } from './lib/utils/datetime_utility';
import { getLocationHash, visitUrl } from './lib/utils/url_utility';
 
// behaviors
Loading
Loading
@@ -43,7 +27,6 @@ import initTodoToggle from './header';
import initImporterStatus from './importer_status';
import initLayoutNav from './layout_nav';
import LazyLoader from './lazy_loader';
import './line_highlighter';
import initLogoAnimation from './logo';
import './milestone_select';
import './projects_dropdown';
Loading
Loading
@@ -55,11 +38,9 @@ import './dispatcher';
// eslint-disable-next-line global-require, import/no-commonjs
if (process.env.NODE_ENV !== 'production') require('./test_utils/');
 
Dropzone.autoDiscover = false;
svg4everybody();
 
document.addEventListener('beforeunload', function () {
document.addEventListener('beforeunload', () => {
// Unbind scroll events
$(document).off('scroll');
// Close any open tooltips
Loading
Loading
@@ -76,16 +57,15 @@ window.addEventListener('load', function onLoad() {
 
gl.lazyLoader = new LazyLoader({
scrollContainer: window,
observerNode: '#content-body'
observerNode: '#content-body',
});
 
$(function () {
var $body = $('body');
var $document = $(document);
var $window = $(window);
var $sidebarGutterToggle = $('.js-sidebar-toggle');
var bootstrapBreakpoint = bp.getBreakpointSize();
var fitSidebarForSize;
$(() => {
const $body = $('body');
const $document = $(document);
const $window = $(window);
const $sidebarGutterToggle = $('.js-sidebar-toggle');
let bootstrapBreakpoint = bp.getBreakpointSize();
 
initBreadcrumbs();
initLayoutNav();
Loading
Loading
@@ -97,8 +77,8 @@ $(function () {
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() {
var href = this.getAttribute('href');
$body.on('click', 'a[href^="#"]', function clickHashLinkCallback() {
const href = this.getAttribute('href');
if (href.substr(1) === getLocationHash()) {
setTimeout(handleLocationHash, 1);
}
Loading
Loading
@@ -113,155 +93,162 @@ $(function () {
}
 
// prevent default action for disabled buttons
$('.btn').click(function(e) {
$('.btn').click(function clickDisabledButtonCallback(e) {
if ($(this).hasClass('disabled')) {
e.preventDefault();
e.stopImmediatePropagation();
return false;
}
return true;
});
 
$('.js-select-on-focus').on('focusin', function () {
return $(this).select().one('mouseup', function (e) {
return e.preventDefault();
});
// Click a .js-select-on-focus field, select the contents
// Prevent a mouseup event from deselecting the input
$('.js-select-on-focus').on('focusin', function selectOnFocusCallback() {
$(this).select().one('mouseup', (e) => {
e.preventDefault();
});
});
$('.remove-row').bind('ajax:success', function () {
$('.remove-row').on('ajax:success', function removeRowAjaxSuccessCallback() {
$(this).tooltip('destroy')
.closest('li')
.fadeOut();
});
$('.js-remove-tr').bind('ajax:before', function () {
return $(this).hide();
$('.js-remove-tr').on('ajax:before', function removeTRAjaxBeforeCallback() {
$(this).hide();
});
$('.js-remove-tr').bind('ajax:success', function () {
return $(this).closest('tr').fadeOut();
$('.js-remove-tr').on('ajax:success', function removeTRAjaxSuccessCallback() {
$(this).closest('tr').fadeOut();
});
// Initialize select2 selects
$('select.select2').select2({
width: 'resolve',
// Initialize select2 selects
dropdownAutoWidth: true
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
$('.js-select2').on('select2-close', () => {
setTimeout(() => {
$('.select2-container-active').removeClass('select2-container-active');
$(':focus').blur();
}, 1);
});
// Initialize tooltips
$.fn.tooltip.Constructor.DEFAULTS.trigger = 'hover';
$body.tooltip({
selector: '.has-tooltip, [data-toggle="tooltip"]',
placement: function (tip, el) {
placement(tip, el) {
return $(el).data('placement') || 'bottom';
}
},
});
// Initialize popovers
$body.popover({
selector: '[data-toggle="popover"]',
trigger: 'focus',
// set the viewport to the main content, excluding the navigation bar, so
// the navigation can't overlap the popover
viewport: '.layout-page'
viewport: '.layout-page',
});
$('.trigger-submit').on('change', function () {
return $(this).parents('form').submit();
// Form submitter
$('.trigger-submit').on('change', function triggerSubmitCallback() {
$(this).parents('form').submit();
});
localTimeAgo($('abbr.timeago, .js-timeago'), true);
// Disable form buttons while a form is submitting
$body.on('ajax:complete, ajax:beforeSend, submit', 'form', function (e) {
var buttons;
buttons = $('[type="submit"], .js-disable-on-submit', this);
$body.on('ajax:complete, ajax:beforeSend, submit', 'form', function ajaxCompleteCallback(e) {
const $buttons = $('[type="submit"], .js-disable-on-submit', this);
switch (e.type) {
case 'ajax:beforeSend':
case 'submit':
return buttons.disable();
return $buttons.disable();
default:
return buttons.enable();
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');
$(document).ajaxError((e, xhrObj) => {
const ref = xhrObj.status;
if (ref === 401) {
Flash('You need to be logged in.');
} else if (ref === 404 || ref === 500) {
return new Flash('Something went wrong on our end.', 'alert');
Flash('Something went wrong on our end.');
}
});
$('.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
$document.on('click', '.diff-content .js-show-suppressed-diff', function showDiffCallback() {
const $container = $(this).parent();
$container.next('table').show();
$container.remove();
});
$('.navbar-toggle').on('click', () => {
$('.header-content').toggleClass('menu-expanded');
gl.lazyLoader.loadCheck();
});
// 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');
$body.on('click', '.js-toggle-diff-comments', function toggleDiffCommentsCallback(e) {
const $this = $(this);
const notesHolders = $this.closest('.diff-file').find('.notes_holder');
e.preventDefault();
$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');
$document.on('click', '.js-confirm-danger', (e) => {
const btn = $(e.target);
const form = btn.closest('form');
const 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());
// eslint-disable-next-line no-new
new ConfirmDangerModal(form, text);
});
$document.off('breakpoint:change').on('breakpoint:change', function (e, breakpoint) {
var $gutterIcon;
$document.on('breakpoint:change', (e, breakpoint) => {
if (breakpoint === 'sm' || breakpoint === 'xs') {
$gutterIcon = $sidebarGutterToggle.find('i');
const $gutterIcon = $sidebarGutterToggle.find('i');
if ($gutterIcon.hasClass('fa-angle-double-right')) {
return $sidebarGutterToggle.trigger('click');
$sidebarGutterToggle.trigger('click');
}
}
});
fitSidebarForSize = function () {
var oldBootstrapBreakpoint;
oldBootstrapBreakpoint = bootstrapBreakpoint;
function fitSidebarForSize() {
const oldBootstrapBreakpoint = bootstrapBreakpoint;
bootstrapBreakpoint = bp.getBreakpointSize();
if (bootstrapBreakpoint !== oldBootstrapBreakpoint) {
return $document.trigger('breakpoint:change', [bootstrapBreakpoint]);
$document.trigger('breakpoint:change', [bootstrapBreakpoint]);
}
};
$window.off('resize.app').on('resize.app', function () {
return fitSidebarForSize();
});
loadAwardsHandler();
}
 
renderTimeago();
$window.on('resize.app', fitSidebarForSize);
loadAwardsHandler();
 
$('form.filter-form').on('submit', function (event) {
$('form.filter-form').on('submit', function filterFormSubmitCallback(event) {
const link = document.createElement('a');
link.href = this.action;
 
Loading
Loading
/* global Sortable */
import Flash from './flash';
 
export default class Milestone {
Loading
Loading
import _ from 'underscore';
import Vue from 'vue';
import VueResource from 'vue-resource';
 
Loading
Loading
/* global Mousetrap */
import Mousetrap from 'mousetrap';
import { getLocationHash, visitUrl } from './lib/utils/url_utility';
import Shortcuts from './shortcuts';
 
Loading
Loading
/* global Mousetrap */
import Mousetrap from 'mousetrap';
import ShortcutsNavigation from './shortcuts_navigation';
 
export default class ShortcutsFindFile extends ShortcutsNavigation {
Loading
Loading
/* global Mousetrap */
import Mousetrap from 'mousetrap';
import _ from 'underscore';
import 'mousetrap';
import Sidebar from './right_sidebar';
import ShortcutsNavigation from './shortcuts_navigation';
import { CopyAsGFM } from './behaviors/copy_as_gfm';
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment