| 1 |
|
| 2 |
|
| 3 |
const |
| 4 |
Vue = require( 'vue' ), |
| 5 |
App = require( './App.vue' ), |
| 6 |
config = require( './config.json' ); |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
function initApp( searchBox ) { |
| 13 |
const searchForm = searchBox.querySelector( '.cdx-search-input' ), |
| 14 |
titleInput = ( |
| 15 |
searchBox.querySelector( 'input[name=title]' ) |
| 16 |
), |
| 17 |
search = ( searchBox.querySelector( 'input[name=search]' ) ), |
| 18 |
searchPageTitle = titleInput && titleInput.value, |
| 19 |
searchContainer = searchBox.querySelector( '.vector-typeahead-search-container' ); |
| 20 |
|
| 21 |
if ( !searchForm || !search || !titleInput ) { |
| 22 |
throw new Error( 'Attempted to create Vue search element from an incompatible element.' ); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
Vue.createMwApp( |
| 27 |
App, Object.assign( { |
| 28 |
id: searchForm.id, |
| 29 |
autocapitalizeValue: search.getAttribute( 'autocapitalize' ), |
| 30 |
autofocusInput: search === document.activeElement, |
| 31 |
action: searchForm.getAttribute( 'action' ), |
| 32 |
searchAccessKey: search.getAttribute( 'accessKey' ), |
| 33 |
searchPageTitle: searchPageTitle, |
| 34 |
searchTitle: search.getAttribute( 'title' ), |
| 35 |
searchPlaceholder: search.getAttribute( 'placeholder' ), |
| 36 |
searchQuery: search.value, |
| 37 |
autoExpandWidth: searchBox ? searchBox.classList.contains( 'vector-search-box-auto-expand-width' ) : false |
| 38 |
|
| 39 |
}, config ) |
| 40 |
) |
| 41 |
.mount( searchContainer ); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
function main( document ) { |
| 48 |
document.querySelectorAll( '.vector-search-box' ) |
| 49 |
.forEach( initApp ); |
| 50 |
} |
| 51 |
main( document ); |