gitlab-org--gitlab-foss/app/assets/javascripts/dispatcher.js

92 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-06-16 09:20:30 -04:00
/* eslint-disable consistent-return, no-new */
import $ from 'jquery';
import Flash from './flash';
import GfmAutoComplete from './gfm_auto_complete';
2018-01-19 12:18:51 -05:00
import { convertPermissionToBoolean } from './lib/utils/common_utils';
import GlFieldErrors from './gl_field_errors';
import Shortcuts from './shortcuts';
2017-12-13 04:26:44 -05:00
import SearchAutocomplete from './search_autocomplete';
2018-02-26 15:01:05 -05:00
function initSearch() {
// Only when search form is present
if ($('.search').length) {
return new SearchAutocomplete();
}
}
2018-02-22 16:48:15 -05:00
2018-02-26 15:01:05 -05:00
function initFieldErrors() {
$('.gl-show-field-errors').each((i, form) => {
new GlFieldErrors(form);
});
}
2018-02-22 16:48:15 -05:00
2018-02-26 15:01:05 -05:00
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',
];
2018-02-26 15:01:05 -05:00
if (pagesWithCustomShortcuts.indexOf(page) === -1) {
new Shortcuts();
}
}
2016-07-24 16:45:11 -04:00
2018-02-26 15:01:05 -05:00
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,
);
2018-02-26 15:01:05 -05:00
gfm.setup($(el), {
emojis: true,
members: enableGFM,
issues: enableGFM,
milestones: enableGFM,
mergeRequests: enableGFM,
labels: enableGFM,
});
});
}
2016-07-24 16:45:11 -04:00
2018-02-26 15:01:05 -05:00
function initPerformanceBar() {
if (document.querySelector('#js-peek')) {
2018-02-26 15:01:05 -05:00
import('./performance_bar')
.then(m => new m.default({ container: '#js-peek' })) // eslint-disable-line new-cap
2018-02-26 15:01:05 -05:00
.catch(() => Flash('Error loading performance bar module'));
}
}
2018-02-26 15:01:05 -05:00
export default () => {
initSearch();
initFieldErrors();
2018-02-26 15:01:05 -05:00
const page = $('body').attr('data-page');
if (page) {
initPageShortcuts(page);
initGFMInput();
initPerformanceBar();
}
};