debian-mirror-gitlab/app/assets/javascripts/dispatcher.js

86 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-arrow-callback, wrap-iife, no-shadow, consistent-return, one-var, one-var-declaration-per-line, camelcase, default-case, no-new, quotes, no-duplicate-case, no-case-declarations, no-fallthrough, max-len */
2018-03-17 18:26:18 +05:30
import Flash from './flash';
2017-09-10 17:25:29 +05:30
import GfmAutoComplete from './gfm_auto_complete';
2018-03-17 18:26:18 +05:30
import { convertPermissionToBoolean } from './lib/utils/common_utils';
import GlFieldErrors from './gl_field_errors';
import Shortcuts from './shortcuts';
import SearchAutocomplete from './search_autocomplete';
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
function initSearch() {
// Only when search form is present
if ($('.search').length) {
return new SearchAutocomplete();
}
}
2017-09-10 17:25:29 +05:30
2018-03-27 19:54:05 +05:30
function initFieldErrors() {
$('.gl-show-field-errors').each((i, form) => {
new GlFieldErrors(form);
});
}
2017-09-10 17:25:29 +05:30
2018-03-27 19:54:05 +05:30
function initPageShortcuts(page) {
const pagesWithCustomShortcuts = [
'projects:activity',
'projects:artifacts:browse',
'projects:artifacts:file',
'projects:blame:show',
'projects:blob:show',
'projects:commit:show',
'projects:commits:show',
'projects:find_file:show',
'projects:issues:edit',
'projects:issues:index',
'projects:issues:new',
'projects:issues:show',
'projects:merge_requests:creations:diffs',
'projects:merge_requests:creations:new',
'projects:merge_requests:edit',
'projects:merge_requests:index',
'projects:merge_requests:show',
'projects:network:show',
'projects:show',
'projects:tree:show',
'groups:show',
];
2017-09-10 17:25:29 +05:30
2018-03-27 19:54:05 +05:30
if (pagesWithCustomShortcuts.indexOf(page) === -1) {
new Shortcuts();
}
}
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
function initGFMInput() {
$('.js-gfm-input:not(.js-vue-textarea)').each((i, el) => {
const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources);
const enableGFM = convertPermissionToBoolean(el.dataset.supportsAutocomplete);
gfm.setup($(el), {
emojis: true,
members: enableGFM,
issues: enableGFM,
milestones: enableGFM,
mergeRequests: enableGFM,
labels: enableGFM,
});
});
}
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
function initPerformanceBar() {
if (document.querySelector('#peek')) {
import('./performance_bar')
.then(m => new m.default({ container: '#peek' })) // eslint-disable-line new-cap
.catch(() => Flash('Error loading performance bar module'));
}
}
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
export default () => {
initSearch();
initFieldErrors();
2017-09-10 17:25:29 +05:30
2018-03-27 19:54:05 +05:30
const page = $('body').attr('data-page');
if (page) {
initPageShortcuts(page);
initGFMInput();
initPerformanceBar();
}
};