mirror of
https://github.com/zhigang1992/docsify.git
synced 2026-04-23 21:00:06 +08:00
Execute script when vue exists.
This commit is contained in:
12
src/index.js
12
src/index.js
@@ -76,11 +76,10 @@ const mainRender = function (cb) {
|
||||
if (OPTIONS.coverpage && page !== OPTIONS.homepage) render.renderCover()
|
||||
// render sidebar
|
||||
if (OPTIONS.loadSidebar) {
|
||||
load(basePath + OPTIONS.loadSidebar)
|
||||
.then(result => {
|
||||
render.renderSidebar(result)
|
||||
cb()
|
||||
})
|
||||
const renderSidebar = result => { render.renderSidebar(result); cb() }
|
||||
|
||||
load(basePath + OPTIONS.loadSidebar).then(renderSidebar,
|
||||
load(OPTIONS.loadSidebar).then(renderSidebar))
|
||||
} else {
|
||||
cb()
|
||||
}
|
||||
@@ -88,7 +87,8 @@ const mainRender = function (cb) {
|
||||
|
||||
// Render navbar
|
||||
if (OPTIONS.loadNavbar) {
|
||||
load(basePath + OPTIONS.loadNavbar).then(render.renderNavbar)
|
||||
load(basePath + OPTIONS.loadNavbar).then(render.renderNavbar,
|
||||
() => load(OPTIONS.loadNavbar).then(render.renderNavbar))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,9 +98,14 @@ export function renderArticle (content) {
|
||||
renderTo('article', content ? markdown(content) : 'not found')
|
||||
if (!OPTIONS.sidebar && !OPTIONS.loadSidebar) renderSidebar()
|
||||
|
||||
if (content && typeof Vue !== 'undefined' && typeof Vuep !== 'undefined') {
|
||||
const vm = new Vue({ el: 'main' }) // eslint-disable-line
|
||||
vm.$nextTick(_ => event.scrollActiveSidebar())
|
||||
if (content && typeof Vue !== 'undefined') {
|
||||
const script = content.match('<script[^>]*?>([^<]+)</script>')
|
||||
script && document.body.querySelector('article script').remove()
|
||||
|
||||
const vm = script
|
||||
? new Function(`return ${script[1].trim()}`)()
|
||||
: new Vue({ el: 'main' }) // eslint-disable-line
|
||||
vm && vm.$nextTick(_ => event.scrollActiveSidebar())
|
||||
}
|
||||
if (OPTIONS.auto2top) setTimeout(() => event.scroll2Top(OPTIONS.auto2top), 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user