2021-09-06 21:02:14 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Translate from '~/vue_shared/translate';
|
|
|
|
import HeaderSearchApp from './components/app.vue';
|
2021-09-09 23:10:59 -04:00
|
|
|
import createStore from './store';
|
2021-09-06 21:02:14 -04:00
|
|
|
|
|
|
|
Vue.use(Translate);
|
|
|
|
|
2022-03-09 22:08:56 -05:00
|
|
|
export const initHeaderSearchApp = (search = '') => {
|
2021-09-06 21:02:14 -04:00
|
|
|
const el = document.getElementById('js-header-search');
|
2022-05-12 23:08:13 -04:00
|
|
|
let navBarEl = null;
|
2021-09-06 21:02:14 -04:00
|
|
|
|
|
|
|
if (!el) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-21 14:11:18 -04:00
|
|
|
const { searchPath, issuesPath, mrPath, autocompletePath } = el.dataset;
|
2021-09-09 23:10:59 -04:00
|
|
|
let { searchContext } = el.dataset;
|
|
|
|
searchContext = JSON.parse(searchContext);
|
|
|
|
|
2021-09-06 21:02:14 -04:00
|
|
|
return new Vue({
|
|
|
|
el,
|
2022-03-09 22:08:56 -05:00
|
|
|
store: createStore({ searchPath, issuesPath, mrPath, autocompletePath, searchContext, search }),
|
2022-05-12 23:08:13 -04:00
|
|
|
mounted() {
|
|
|
|
navBarEl = document.querySelector('.header-content');
|
|
|
|
},
|
2021-09-06 21:02:14 -04:00
|
|
|
render(createElement) {
|
2022-05-12 23:08:13 -04:00
|
|
|
return createElement(HeaderSearchApp, {
|
|
|
|
on: {
|
2022-08-17 11:11:57 -04:00
|
|
|
expandSearchBar: () => {
|
|
|
|
navBarEl?.classList.add('header-search-is-active');
|
|
|
|
},
|
|
|
|
collapseSearchBar: () => {
|
|
|
|
navBarEl?.classList.remove('header-search-is-active');
|
2022-05-12 23:08:13 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2021-09-06 21:02:14 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|