2018-06-16 09:20:30 -04:00
|
|
|
/* eslint-disable consistent-return, no-new */
|
2018-03-09 15:18:59 -05:00
|
|
|
|
|
|
|
import $ from 'jquery';
|
2017-10-24 00:56:39 -04:00
|
|
|
import Flash from './flash';
|
2017-05-16 14:42:06 -04:00
|
|
|
import GfmAutoComplete from './gfm_auto_complete';
|
2018-01-19 12:18:51 -05:00
|
|
|
import { convertPermissionToBoolean } from './lib/utils/common_utils';
|
2017-10-10 04:09:01 -04:00
|
|
|
import GlFieldErrors from './gl_field_errors';
|
2017-10-10 05:10:11 -04:00
|
|
|
import Shortcuts from './shortcuts';
|
2017-12-13 04:26:44 -05:00
|
|
|
import SearchAutocomplete from './search_autocomplete';
|
2017-01-25 22:13:01 -05:00
|
|
|
|
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',
|
|
|
|
];
|
2017-07-06 15:37:31 -04:00
|
|
|
|
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) => {
|
2018-03-19 15:06:09 -04:00
|
|
|
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() {
|
2018-03-19 15:06:09 -04:00
|
|
|
if (document.querySelector('#js-peek')) {
|
2018-02-26 15:01:05 -05:00
|
|
|
import('./performance_bar')
|
2018-03-19 15:06:09 -04:00
|
|
|
.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'));
|
|
|
|
}
|
|
|
|
}
|
2016-09-09 08:21:00 -04:00
|
|
|
|
2018-02-26 15:01:05 -05:00
|
|
|
export default () => {
|
|
|
|
initSearch();
|
|
|
|
initFieldErrors();
|
2017-08-03 16:31:53 -04:00
|
|
|
|
2018-02-26 15:01:05 -05:00
|
|
|
const page = $('body').attr('data-page');
|
|
|
|
if (page) {
|
|
|
|
initPageShortcuts(page);
|
|
|
|
initGFMInput();
|
|
|
|
initPerformanceBar();
|
|
|
|
}
|
|
|
|
};
|