2020-11-19 17:12:53 +00:00
|
|
|
<template>
|
2021-04-21 12:48:02 +00:00
|
|
|
<wvui-typeahead-search
|
2021-09-09 21:40:06 +00:00
|
|
|
:id="id"
|
2021-04-21 12:48:02 +00:00
|
|
|
ref="searchForm"
|
|
|
|
:client="getClient"
|
|
|
|
:domain="domain"
|
2021-05-26 21:13:43 +00:00
|
|
|
:suggestions-label="$i18n( 'searchresults' ).text()"
|
2021-04-21 12:48:02 +00:00
|
|
|
:accesskey="searchAccessKey"
|
|
|
|
:title="searchTitle"
|
|
|
|
:placeholder="searchPlaceholder"
|
|
|
|
:aria-label="searchPlaceholder"
|
2021-07-28 16:15:57 +00:00
|
|
|
:search-page-title="searchPageTitle"
|
2021-04-21 12:48:02 +00:00
|
|
|
:initial-input-value="searchQuery"
|
2021-05-26 21:13:43 +00:00
|
|
|
:button-label="$i18n( 'searchbutton' ).text()"
|
2021-04-21 12:48:02 +00:00
|
|
|
:form-action="action"
|
|
|
|
:search-language="language"
|
|
|
|
:show-thumbnail="showThumbnail"
|
|
|
|
:show-description="showDescription"
|
2021-05-25 10:40:49 +00:00
|
|
|
:highlight-query="highlightQuery"
|
2021-12-16 03:13:56 +00:00
|
|
|
:auto-expand-width="autoExpandWidth"
|
2021-04-21 12:48:02 +00:00
|
|
|
@fetch-start="instrumentation.onFetchStart"
|
|
|
|
@fetch-end="instrumentation.onFetchEnd"
|
|
|
|
@suggestion-click="instrumentation.onSuggestionClick"
|
2021-05-13 14:25:53 +00:00
|
|
|
@submit="onSubmit"
|
2021-04-21 12:48:02 +00:00
|
|
|
>
|
2021-09-30 20:52:16 +00:00
|
|
|
<template #default>
|
|
|
|
<input type="hidden"
|
|
|
|
name="title"
|
|
|
|
:value="searchPageTitle"
|
|
|
|
>
|
|
|
|
<input type="hidden"
|
|
|
|
name="wprov"
|
|
|
|
:value="wprov"
|
|
|
|
>
|
|
|
|
</template>
|
|
|
|
<template #search-footer-text="{ searchQuery }">
|
|
|
|
<span v-i18n-html:vector-searchsuggest-containing="[ searchQuery ]"></span>
|
|
|
|
</template>
|
2021-04-21 12:48:02 +00:00
|
|
|
</wvui-typeahead-search>
|
2020-11-19 17:12:53 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-11-24 22:16:03 +00:00
|
|
|
/* global SubmitEvent */
|
2022-01-31 21:43:32 +00:00
|
|
|
const wvui = require( 'wvui-search' ),
|
2022-02-02 21:17:56 +00:00
|
|
|
client = require( './restSearchClient.js' ),
|
2020-11-24 22:16:03 +00:00
|
|
|
instrumentation = require( './instrumentation.js' );
|
2020-11-19 17:12:53 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'App',
|
|
|
|
components: wvui,
|
2022-01-31 21:43:32 +00:00
|
|
|
mounted() {
|
2020-11-19 17:12:53 +00:00
|
|
|
// access the element associated with the wvui-typeahead-search component
|
|
|
|
// eslint-disable-next-line no-jquery/variable-pattern
|
2022-01-31 21:43:32 +00:00
|
|
|
const wvuiSearchForm = this.$refs.searchForm.$el;
|
2020-11-19 17:12:53 +00:00
|
|
|
|
|
|
|
if ( this.autofocusInput ) {
|
|
|
|
// TODO: The wvui-typeahead-search component does not accept an autofocus parameter
|
|
|
|
// or directive. This can be removed when its does.
|
|
|
|
wvuiSearchForm.querySelector( 'input' ).focus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2020-12-22 20:08:47 +00:00
|
|
|
/**
|
|
|
|
* Allow wikis eg. Hebrew Wikipedia to replace the default search API client
|
|
|
|
*
|
2022-02-02 21:17:56 +00:00
|
|
|
* @return {module:restSearchClient~SearchClient}
|
2020-12-22 20:08:47 +00:00
|
|
|
*/
|
2022-01-31 21:43:32 +00:00
|
|
|
getClient: () => {
|
2022-02-02 21:17:56 +00:00
|
|
|
return client( mw.config );
|
2020-12-22 20:08:47 +00:00
|
|
|
},
|
2022-01-31 21:43:32 +00:00
|
|
|
language: () => {
|
2020-11-19 17:12:53 +00:00
|
|
|
return mw.config.get( 'wgUserLanguage' );
|
|
|
|
},
|
2022-01-31 21:43:32 +00:00
|
|
|
domain: () => {
|
2020-11-19 17:12:53 +00:00
|
|
|
// It might be helpful to allow this to be configurable in future.
|
2020-11-23 22:55:35 +00:00
|
|
|
return mw.config.get( 'wgVectorSearchHost', location.host );
|
2020-11-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
props: {
|
2021-09-09 21:40:06 +00:00
|
|
|
id: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
},
|
2021-07-28 16:15:57 +00:00
|
|
|
searchPageTitle: {
|
|
|
|
type: String,
|
|
|
|
default: 'Special:Search'
|
|
|
|
},
|
2020-11-19 17:12:53 +00:00
|
|
|
autofocusInput: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
action: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
/** The keyboard shortcut to focus search. */
|
|
|
|
searchAccessKey: {
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
/** The access key informational tip for search. */
|
|
|
|
searchTitle: {
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
/** The ghost text shown when no search query is entered. */
|
|
|
|
searchPlaceholder: {
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The search query string taken from the server-side rendered input immediately before
|
|
|
|
* client render.
|
|
|
|
*/
|
|
|
|
searchQuery: {
|
|
|
|
type: String
|
2020-11-26 00:58:10 +00:00
|
|
|
},
|
|
|
|
showThumbnail: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
showDescription: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
2021-05-25 10:40:49 +00:00
|
|
|
},
|
|
|
|
highlightQuery: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
2021-12-16 03:13:56 +00:00
|
|
|
},
|
|
|
|
autoExpandWidth: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2020-11-19 17:12:53 +00:00
|
|
|
}
|
2020-11-24 22:16:03 +00:00
|
|
|
},
|
2022-01-31 21:43:32 +00:00
|
|
|
data() {
|
2020-11-24 22:16:03 +00:00
|
|
|
return {
|
|
|
|
// -1 here is the default "active suggestion index" defined in the
|
|
|
|
// `wvui-typeahead-search` component (see
|
|
|
|
// https://gerrit.wikimedia.org/r/plugins/gitiles/wvui/+/c7af5d6d091ffb3beb4fd2723fdf50dc6bb2789b/src/components/typeahead-search/TypeaheadSearch.vue#167).
|
|
|
|
wprov: instrumentation.getWprovFromResultIndex( -1 ),
|
|
|
|
|
|
|
|
instrumentation: instrumentation.listeners
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
/**
|
|
|
|
* @param {SubmitEvent} event
|
|
|
|
*/
|
2022-01-31 21:43:32 +00:00
|
|
|
onSubmit( event ) {
|
2020-11-24 22:16:03 +00:00
|
|
|
this.wprov = instrumentation.getWprovFromResultIndex( event.index );
|
|
|
|
|
|
|
|
instrumentation.listeners.onSubmit( event );
|
|
|
|
}
|
2020-11-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|