summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/header_search/index.js
blob: f6f5c6a14faaa3f3d6bcdaee0427d7b61f534feb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Vue from 'vue';
import Translate from '~/vue_shared/translate';
import HeaderSearchApp from './components/app.vue';
import createStore from './store';

Vue.use(Translate);

export const initHeaderSearchApp = (search = '') => {
  const el = document.getElementById('js-header-search');
  let navBarEl = null;

  if (!el) {
    return false;
  }

  const { searchPath, issuesPath, mrPath, autocompletePath } = el.dataset;
  let { searchContext } = el.dataset;
  searchContext = JSON.parse(searchContext);

  return new Vue({
    el,
    store: createStore({ searchPath, issuesPath, mrPath, autocompletePath, searchContext, search }),
    mounted() {
      navBarEl = document.querySelector('.header-content');
    },
    render(createElement) {
      return createElement(HeaderSearchApp, {
        on: {
          expandSearchBar: () => {
            navBarEl?.classList.add('header-search-is-active');
          },
          collapseSearchBar: () => {
            navBarEl?.classList.remove('header-search-is-active');
          },
        },
      });
    },
  });
};