refactor(plugins): update search plugin

This commit is contained in:
qingwei.li 2017-02-19 10:47:47 +08:00 • committed by cinwell.li
commit 079bd00395
22 changed files with 348 additions and 393 deletions

View file

@ -0,0 +1,31 @@
import initComponet from './component'
import { init as initSearch } from './search'
const CONFIG = {
placeholder: 'Type to search',
paths: 'auto',
maxAge: 86400000 // 1 day
}
const install = function (hook, vm) {
const util = Docsify.util
const opts = vm.config.search
if (Array.isArray(opts)) {
CONFIG.paths = opts
} else if (typeof opts === 'object') {
CONFIG.paths = Array.isArray(opts.paths) ? opts.paths : 'auto'
CONFIG.maxAge = util.isPrimitive(opts.maxAge) ? opts.maxAge : CONFIG.maxAge
CONFIG.placeholder = opts.placeholder || CONFIG.placeholder
}
const isAuto = CONFIG.paths === 'auto'
hook.ready(_ => {
initComponet(CONFIG)
isAuto && initSearch(CONFIG, vm)
})
!isAuto && hook.doneEach(_ => initSearch(CONFIG, vm))
}
window.$docsify.plugins = [].concat(install, window.$docsify.plugins)