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

90 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
/* eslint-disable consistent-return, no-new */
2018-05-09 12:01:36 +05:30
import $ from 'jquery';
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';
2018-11-08 19:23:39 +05:30
import performanceBar from './performance_bar';
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) => {
2018-05-09 12:01:36 +05:30
const gfm = new GfmAutoComplete(
gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources,
);
const enableGFM = convertPermissionToBoolean(
el.dataset.supportsAutocomplete,
);
2018-03-27 19:54:05 +05:30
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() {
2018-05-09 12:01:36 +05:30
if (document.querySelector('#js-peek')) {
2018-11-08 19:23:39 +05:30
performanceBar({ container: '#js-peek' });
2018-03-27 19:54:05 +05:30
}
}
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();
}
};