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