feat(search): Localization for search placeholder, close #80
This commit is contained in:
parent
079bd00395
commit
2351c3e68c
6 changed files with 41 additions and 6 deletions
|
|
@ -67,7 +67,7 @@ function style () {
|
|||
|
||||
function tpl (opts) {
|
||||
const html =
|
||||
`<input type="search" placeholder="${opts.placeholder}" />` +
|
||||
`<input type="search" />` +
|
||||
'<div class="results-panel"></div>' +
|
||||
'</div>'
|
||||
const el = dom.create('div', html)
|
||||
|
|
@ -108,9 +108,25 @@ function bindEvents () {
|
|||
})
|
||||
}
|
||||
|
||||
export default function (opts) {
|
||||
function updatePlaceholder (text, path) {
|
||||
const $input = dom.getNode('.search input[type="search"]')
|
||||
|
||||
if (typeof text === 'string') {
|
||||
$input.placeholder = text
|
||||
} else {
|
||||
const match = Object.keys(text).find(key => path.indexOf(key) > -1)
|
||||
$input.placeholder = text[match]
|
||||
}
|
||||
}
|
||||
|
||||
export function init (opts) {
|
||||
dom = Docsify.dom
|
||||
style()
|
||||
tpl(opts)
|
||||
bindEvents()
|
||||
}
|
||||
|
||||
export function update (opts, vm) {
|
||||
updatePlaceholder(opts.placeholder, vm.route.path)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue