Skip to content

Fix/buglist #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function scrollActiveSidebar () {
let hoveredOverSidebar = false
const anchors = document.querySelectorAll('.anchor')
const sidebar = document.querySelector('.sidebar')
const sidebarContainer = sidebar.querySelector('.sidebar-nav')
const sidebarHeight = sidebar.clientHeight

const nav = {}
Expand Down Expand Up @@ -57,12 +58,12 @@ export function scrollActiveSidebar () {
const currentPageOffset = 0
const currentActiveOffset = active.offsetTop + active.clientHeight + 40
const currentActiveIsInView = (
active.offsetTop >= sidebar.scrollTop &&
currentActiveOffset <= sidebar.scrollTop + sidebarHeight
active.offsetTop >= sidebarContainer.scrollTop &&
currentActiveOffset <= sidebarContainer.scrollTop + sidebarHeight
)
const linkNotFurtherThanSidebarHeight = currentActiveOffset - currentPageOffset < sidebarHeight
const newScrollTop = currentActiveIsInView
? sidebar.scrollTop
? sidebarContainer.scrollTop
: linkNotFurtherThanSidebarHeight
? currentPageOffset
: currentActiveOffset - sidebarHeight
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const genIndex = function (path, content = '') {
slug = `#/${path}#${id}`.replace(/\/+/, '/')
INDEXS[slug] = { slug, title: text, body: '' }
} else {
if (!slug) return
// other html tag
if (!INDEXS[slug]) {
INDEXS[slug] = {}
Expand Down Expand Up @@ -180,9 +181,11 @@ class SearchComponent {
}

bindEvent () {
const input = document.querySelector('.search input')
const panel = document.querySelector('.results-panel')
const search = document.querySelector('.search')
const input = search.querySelector('.search input')
const panel = search.querySelector('.results-panel')

search.addEventListener('click', e => e.target.tagName !== 'A' && e.stopPropagation())
input.addEventListener('input', e => {
const target = e.target

Expand Down