Move search autocomplete from dispatcher to main.js
This commit is contained in:
parent
dc2b81c8e8
commit
05f403cf04
4 changed files with 10 additions and 13 deletions
|
@ -4,16 +4,8 @@ import $ from 'jquery';
|
|||
import GfmAutoComplete from './gfm_auto_complete';
|
||||
import { convertPermissionToBoolean } from './lib/utils/common_utils';
|
||||
import Shortcuts from './shortcuts';
|
||||
import SearchAutocomplete from './search_autocomplete';
|
||||
import performanceBar from './performance_bar';
|
||||
|
||||
function initSearch() {
|
||||
// Only when search form is present
|
||||
if ($('.search').length) {
|
||||
return new SearchAutocomplete();
|
||||
}
|
||||
}
|
||||
|
||||
function initPageShortcuts(page) {
|
||||
const pagesWithCustomShortcuts = [
|
||||
'projects:activity',
|
||||
|
@ -70,8 +62,6 @@ function initPerformanceBar() {
|
|||
}
|
||||
|
||||
export default () => {
|
||||
initSearch();
|
||||
|
||||
const page = $('body').attr('data-page');
|
||||
if (page) {
|
||||
initPageShortcuts(page);
|
||||
|
|
|
@ -28,6 +28,7 @@ import './frequent_items';
|
|||
import initBreadcrumbs from './breadcrumb';
|
||||
import initDispatcher from './dispatcher';
|
||||
import initUsagePingConsent from './usage_ping_consent';
|
||||
import initSearchAutocomplete from './search_autocomplete';
|
||||
import GlFieldErrors from './gl_field_errors';
|
||||
|
||||
// expose jQuery as global (TODO: remove these)
|
||||
|
@ -78,6 +79,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
initLogoAnimation();
|
||||
initUsagePingConsent();
|
||||
|
||||
if (document.querySelector('.search')) initSearchAutocomplete();
|
||||
|
||||
// Set the default path for all cookies to GitLab's root directory
|
||||
Cookies.defaults.path = gon.relative_url_root || '/';
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ function setSearchOptions() {
|
|||
}
|
||||
}
|
||||
|
||||
export default class SearchAutocomplete {
|
||||
export class SearchAutocomplete {
|
||||
constructor({ wrap, optsEl, autocompletePath, projectId, projectRef } = {}) {
|
||||
setSearchOptions();
|
||||
this.bindEventContext();
|
||||
|
@ -499,3 +499,7 @@ export default class SearchAutocomplete {
|
|||
this.dropdownMenu.toggleClass('fade-out', !this.isScrolledUp());
|
||||
}
|
||||
}
|
||||
|
||||
export default function initSearchAutocomplete(opts) {
|
||||
return new SearchAutocomplete(opts);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import $ from 'jquery';
|
||||
import '~/gl_dropdown';
|
||||
import SearchAutocomplete from '~/search_autocomplete';
|
||||
import initSearchAutocomplete from '~/search_autocomplete';
|
||||
import '~/lib/utils/common_utils';
|
||||
|
||||
describe('Search autocomplete dropdown', () => {
|
||||
|
@ -132,7 +132,7 @@ describe('Search autocomplete dropdown', () => {
|
|||
window.gon.current_user_id = userId;
|
||||
window.gon.current_username = userName;
|
||||
|
||||
return (widget = new SearchAutocomplete());
|
||||
return (widget = initSearchAutocomplete());
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
|
|
Loading…
Reference in a new issue