fix(ssr): remove context

This commit is contained in:
qingwei.li 2017-05-30 06:32:41 +08:00
commit 46261572e3
No known key found for this signature in database
GPG key ID: B6DDC2F7AE80B2F4
12 changed files with 58 additions and 59 deletions

View file

@ -1,6 +1,5 @@
import { search } from './search'
let dom
let NO_DATA_TEXT = ''
function style () {
@ -65,8 +64,8 @@ function style () {
.search p.empty {
text-align: center;
}`
const style = dom.create('style', code)
dom.appendTo(dom.head, style)
const style = Docsify.dom.create('style', code)
Docsify.dom.appendTo(Docsify.dom.head, style)
}
function tpl (opts, defaultValue = '') {
@ -74,16 +73,16 @@ function tpl (opts, defaultValue = '') {
`<input type="search" value="${defaultValue}" />` +
'<div class="results-panel"></div>' +
'</div>'
const el = dom.create('div', html)
const aside = dom.find('aside')
const el = Docsify.dom.create('div', html)
const aside = Docsify.dom.find('aside')
dom.toggleClass(el, 'search')
dom.before(aside, el)
Docsify.dom.toggleClass(el, 'search')
Docsify.dom.before(aside, el)
}
function doSearch (value) {
const $search = dom.find('div.search')
const $panel = dom.find($search, '.results-panel')
const $search = Docsify.dom.find('div.search')
const $panel = Docsify.dom.find($search, '.results-panel')
if (!value) {
$panel.classList.remove('show')
@ -105,22 +104,23 @@ function doSearch (value) {
}
function bindEvents () {
const $search = dom.find('div.search')
const $input = dom.find($search, 'input')
const $search = Docsify.dom.find('div.search')
const $input = Docsify.dom.find($search, 'input')
let timeId
// Prevent to Fold sidebar
dom.on($search, 'click',
Docsify.dom.on($search, 'click',
e => e.target.tagName !== 'A' && e.stopPropagation())
dom.on($input, 'input', e => {
Docsify.dom.on($input, 'input', e => {
clearTimeout(timeId)
timeId = setTimeout(_ => doSearch(e.target.value.trim()), 100)
})
}
function updatePlaceholder (text, path) {
const $input = dom.getNode('.search input[type="search"]')
const $input = Docsify.dom.getNode('.search input[type="search"]')
if (!$input) return
if (typeof text === 'string') {
$input.placeholder = text
} else {
@ -139,7 +139,6 @@ function updateNoData (text, path) {
}
export function init (opts, vm) {
dom = Docsify.dom
const keywords = vm.router.parse().query.s
style()

View file

@ -41,13 +41,12 @@ function saveData (maxAge) {
export function genIndex (path, content = '', router) {
const tokens = window.marked.lexer(content)
const slugify = window.Docsify.slugify
const toURL = router.toURL
const index = {}
let slug
tokens.forEach(token => {
if (token.type === 'heading' && token.depth <= 2) {
slug = toURL(path, { id: slugify(token.text) })
slug = router.toURL(path, { id: slugify(token.text) })
index[slug] = { slug, title: token.text, body: '' }
} else {
if (!slug) return