diff options
author | Mike Greiling <mike@pixelcog.com> | 2018-09-13 16:59:09 -0500 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2018-09-14 01:22:53 -0500 |
commit | 05f403cf046912b53c4b4f4dae48d4b8cc375812 (patch) | |
tree | 4fdc34cfc977021d058c95b095edf3bd03c67584 /app | |
parent | dc2b81c8e81d9b1d14b76da011722be0c5516988 (diff) | |
download | gitlab-ce-05f403cf046912b53c4b4f4dae48d4b8cc375812.tar.gz |
Move search autocomplete from dispatcher to main.js
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/dispatcher.js | 10 | ||||
-rw-r--r-- | app/assets/javascripts/main.js | 3 | ||||
-rw-r--r-- | app/assets/javascripts/search_autocomplete.js | 6 |
3 files changed, 8 insertions, 11 deletions
diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js index 192d8ca60fe..1186e9e4d95 100644 --- a/app/assets/javascripts/dispatcher.js +++ b/app/assets/javascripts/dispatcher.js @@ -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); diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 393d195549f..a7179686aef 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -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 || '/'; diff --git a/app/assets/javascripts/search_autocomplete.js b/app/assets/javascripts/search_autocomplete.js index aec09b8bc0a..50dd3c12382 100644 --- a/app/assets/javascripts/search_autocomplete.js +++ b/app/assets/javascripts/search_autocomplete.js @@ -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); +} |