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"
|
2022-03-23 17:37:39 +00:00
|
|
|
:article-path="articlePath"
|
2021-04-21 12:48:02 +00:00
|
|
|
: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>
|
2022-03-16 23:40:42 +00:00
|
|
|
<input type="hidden"
|
2021-09-30 20:52:16 +00:00
|
|
|
name="title"
|
|
|
|
:value="searchPageTitle"
|
|
|
|
>
|
2022-03-16 23:40:42 +00:00
|
|
|
<input type="hidden"
|
2021-09-30 20:52:16 +00:00
|
|
|
name="wprov"
|
|
|
|
:value="wprov"
|
|
|
|
>
|
|
|
|
</template>
|
2022-03-16 23:40:42 +00:00
|
|
|
<template #search-footer-text="{ searchQuery }">
|
2021-09-30 20:52:16 +00:00
|
|
|
<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',
|
2022-03-16 23:40:42 +00:00
|
|
|
components: wvui,
|
|
|
|
mounted() {
|
|
|
|
// access the element associated with the wvui-typeahead-search component
|
|
|
|
// eslint-disable-next-line no-jquery/variable-pattern
|
|
|
|
const wvuiSearchForm = this.$refs.searchForm.$el;
|
|
|
|
|
|
|
|
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: {
|
2022-03-23 17:37:39 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
articlePath: () => mw.config.get( 'wgScript' ),
|
2022-03-16 23:40:42 +00:00
|
|
|
/**
|
|
|
|
* Allow wikis eg. Hebrew Wikipedia to replace the default search API client
|
|
|
|
*
|
|
|
|
* @return {module:restSearchClient~SearchClient}
|
|
|
|
*/
|
|
|
|
getClient: () => {
|
|
|
|
return client( mw.config );
|
|
|
|
},
|
|
|
|
language: () => {
|
|
|
|
return mw.config.get( 'wgUserLanguage' );
|
|
|
|
},
|
|
|
|
domain: () => {
|
|
|
|
// It might be helpful to allow this to be configurable in future.
|
|
|
|
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: {
|
2022-03-16 23:40:42 +00:00
|
|
|
type: String
|
2020-11-19 17:12:53 +00:00
|
|
|
},
|
|
|
|
/** The access key informational tip for search. */
|
|
|
|
searchTitle: {
|
2022-03-16 23:40:42 +00:00
|
|
|
type: String
|
2020-11-19 17:12:53 +00:00
|
|
|
},
|
|
|
|
/** The ghost text shown when no search query is entered. */
|
|
|
|
searchPlaceholder: {
|
2022-03-16 23:40:42 +00:00
|
|
|
type: String
|
2020-11-19 17:12:53 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The search query string taken from the server-side rendered input immediately before
|
|
|
|
* client render.
|
|
|
|
*/
|
|
|
|
searchQuery: {
|
2022-03-16 23:40:42 +00:00
|
|
|
type: String
|
2020-11-26 00:58:10 +00:00
|
|
|
},
|
|
|
|
showThumbnail: {
|
2022-03-16 23:40:42 +00:00
|
|
|
type: Boolean,
|
|
|
|
default: true
|
2020-11-26 00:58:10 +00:00
|
|
|
},
|
|
|
|
showDescription: {
|
2022-03-16 23:40:42 +00:00
|
|
|
type: Boolean,
|
|
|
|
default: true
|
2021-05-25 10:40:49 +00:00
|
|
|
},
|
|
|
|
highlightQuery: {
|
2022-03-16 23:40:42 +00:00
|
|
|
type: Boolean,
|
|
|
|
default: true
|
2021-12-16 03:13:56 +00:00
|
|
|
},
|
|
|
|
autoExpandWidth: {
|
2022-03-16 23:40:42 +00:00
|
|
|
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>
|