-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5783ca6
commit e864d75
Showing
3 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<template> | ||
<wvui-typeahead-search | ||
id="searchform" | ||
ref="searchForm" | ||
:client="getClient" | ||
:domain="domain" | ||
:footer-search-text="$i18n('searchsuggest-containing').text()" | ||
:suggestions-label="$i18n('searchresults').text()" | ||
:accesskey="searchAccessKey" | ||
:title="searchTitle" | ||
:placeholder="searchPlaceholder" | ||
:aria-label="searchPlaceholder" | ||
:initial-input-value="searchQuery" | ||
:button-label="$i18n('searchbutton').text()" | ||
:form-action="action" | ||
:search-language="language" | ||
:show-thumbnail="showThumbnail" | ||
:show-description="showDescription" | ||
> | ||
<input type="hidden" name="title" value="Special:Search" /> | ||
</wvui-typeahead-search> | ||
</template> | ||
|
||
<script> | ||
/* global SubmitEvent */ | ||
const wvui = require("wvui"); | ||
module.exports = { | ||
name: "App", | ||
components: wvui, | ||
mounted: function () { | ||
// access the element associated with the wvui-typeahead-search component | ||
// eslint-disable-next-line no-jquery/variable-pattern | ||
var wvuiSearchForm = this.$refs.searchForm.$el; | ||
if (this.autofocusInput) { | ||
// TODO: The wvui-typeahead-search component accepts an id prop but does not | ||
// display that value as an HTML attribute on the form element. | ||
wvuiSearchForm.querySelector("form").setAttribute("id", "searchform"); | ||
// 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: { | ||
/** | ||
* Allow wikis to replace the default search API client | ||
* | ||
* @return {void|Object} | ||
*/ | ||
getClient: function () { | ||
return mw.config.get("wgLakeusSearchClient", undefined); | ||
}, | ||
language: function () { | ||
return mw.config.get("wgUserLanguage"); | ||
}, | ||
domain: function () { | ||
// It might be helpful to allow this to be configurable in future. | ||
return mw.config.get("wgLakeusSearchHost", location.host); | ||
}, | ||
}, | ||
props: { | ||
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, | ||
}, | ||
showThumbnail: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
showDescription: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
}, | ||
data: function () { | ||
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). | ||
}; | ||
}, | ||
methods: { | ||
/** | ||
* @param {SubmitEvent} event | ||
*/ | ||
onSubmit: function (event) {}, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** @module search */ | ||
var Vue = require("vue").default || require("vue"), | ||
App = require("./App.vue"), | ||
config = require("./config.json"); | ||
/** | ||
* @param {HTMLElement} searchForm | ||
* @param {HTMLInputElement} search | ||
* @return {void} | ||
*/ | ||
function initApp(searchForm, search) { | ||
// eslint-disable-next-line no-new | ||
new Vue({ | ||
el: searchForm, | ||
/** | ||
* | ||
* @param {Function} createElement | ||
* @return {Vue.VNode} | ||
*/ | ||
render: function (createElement) { | ||
return createElement(App, { | ||
props: $.extend( | ||
{ | ||
autofocusInput: search === document.activeElement, | ||
action: searchForm.getAttribute("action"), | ||
searchAccessKey: search.getAttribute("accessKey"), | ||
searchTitle: search.getAttribute("title"), | ||
searchPlaceholder: search.getAttribute("placeholder"), | ||
searchQuery: search.value, | ||
}, | ||
// Pass additional config from server. | ||
config | ||
), | ||
}); | ||
}, | ||
}); | ||
} | ||
/** | ||
* @param {Document} document | ||
* @return {void} | ||
*/ | ||
function main(document) { | ||
var searchForm = /** @type {HTMLElement} */ (document.querySelector("#searchform")), | ||
search = /** @type {HTMLInputElement|null} */ (document.getElementById("searchInput")); | ||
if (search && searchForm) { | ||
initApp(searchForm, search); | ||
} | ||
} | ||
main(document); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters