From 1d1c9d811015e4e51f1a484ac1c34bb90ef953f5 Mon Sep 17 00:00:00 2001 From: LaySent Date: Wed, 11 Oct 2017 16:15:19 +0800 Subject: [PATCH 1/4] fix scroll issue in IE --- src/core/event/scroll.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/event/scroll.js b/src/core/event/scroll.js index bba7aecb3..0f77efdc4 100644 --- a/src/core/event/scroll.js +++ b/src/core/event/scroll.js @@ -12,8 +12,8 @@ function scrollTo (el) { if (scroller) scroller.stop() enableScrollEvent = false scroller = new Tweezer({ - start: window.scrollY, - end: el.getBoundingClientRect().top + window.scrollY, + start: window.pageYOffset, + end: el.getBoundingClientRect().top + window.pageYOffset, duration: 500 }) .on('tick', v => window.scrollTo(0, v)) From 57afb0ae46036f353673eb15be2eeb610c19fc21 Mon Sep 17 00:00:00 2001 From: LaySent Date: Wed, 11 Oct 2017 16:56:04 +0800 Subject: [PATCH 2/4] add meta tag for IE browser --- dev.html | 1 + docs/index.html | 1 + 2 files changed, 2 insertions(+) diff --git a/dev.html b/dev.html index f41f01f38..a19a0d5a1 100644 --- a/dev.html +++ b/dev.html @@ -3,6 +3,7 @@ docsify + diff --git a/docs/index.html b/docs/index.html index 28503bad2..3f5400ed9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -4,6 +4,7 @@ docsify + From 61f0e826614bd42e25df5a611e333b97bc5133e4 Mon Sep 17 00:00:00 2001 From: LaySent Date: Thu, 12 Oct 2017 18:16:49 +0800 Subject: [PATCH 3/4] fix link render issue after page refreshing --- src/core/router/history/hash.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/router/history/hash.js b/src/core/router/history/hash.js index ce8335a4a..014a11b15 100644 --- a/src/core/router/history/hash.js +++ b/src/core/router/history/hash.js @@ -80,7 +80,9 @@ export class HashHistory extends History { path = route.path + stringifyQuery(route.query) path = path.replace(/\.md(\?)|\.md$/, '$1') - if (local) path = currentRoute + path + if (local) { + path = currentRoute.substr(0, currentRoute.indexOf('?')) + path + } return cleanPath('#/' + path) } From ee4b3adb0de78a98bf70a32c9307b788f2c257c4 Mon Sep 17 00:00:00 2001 From: LaySent Date: Sun, 15 Oct 2017 20:20:48 +0800 Subject: [PATCH 4/4] fix issue of incorrect active link Should use both `path` and `id` to identify link, as `id` might not be unique under different paths --- src/core/event/index.js | 2 +- src/core/event/scroll.js | 11 ++++++++--- src/core/router/history/hash.js | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/event/index.js b/src/core/event/index.js index 8489fc13e..79e2d1f34 100644 --- a/src/core/event/index.js +++ b/src/core/event/index.js @@ -5,7 +5,7 @@ import { scrollIntoView } from './scroll' export function eventMixin (proto) { proto.$resetEvents = function () { - scrollIntoView(this.route.query.id) + scrollIntoView(this.route.path, this.route.query.id) sidebar.getAndActive(this.router, 'nav') } } diff --git a/src/core/event/scroll.js b/src/core/event/scroll.js index 0f77efdc4..9aa206354 100644 --- a/src/core/event/scroll.js +++ b/src/core/event/scroll.js @@ -68,6 +68,10 @@ function highlight () { } } +function getNavKey (path, id) { + return `${path}?id=${id}` +} + export function scrollActiveSidebar (router) { const cover = dom.find('.cover.show') coverHeight = cover ? cover.offsetHeight : 0 @@ -82,7 +86,8 @@ export function scrollActiveSidebar (router) { let href = a.getAttribute('href') if (href !== '/') { - href = router.parse(href).query.id + const { query: { id }, path } = router.parse(href) + if (id) href = getNavKey(path, id) } if (href) nav[decodeURIComponent(href)] = li @@ -100,13 +105,13 @@ export function scrollActiveSidebar (router) { }) } -export function scrollIntoView (id) { +export function scrollIntoView (path, id) { if (!id) return const section = dom.find('#' + id) section && scrollTo(section) - const li = nav[id] + const li = nav[getNavKey(path, id)] const sidebar = dom.getNode('.sidebar') const active = dom.find(sidebar, 'li.active') active && active.classList.remove('active') diff --git a/src/core/router/history/hash.js b/src/core/router/history/hash.js index eccc6faeb..37858521d 100644 --- a/src/core/router/history/hash.js +++ b/src/core/router/history/hash.js @@ -55,7 +55,7 @@ export class HashHistory extends History { let query = '' const hashIndex = path.indexOf('#') - if (hashIndex) { + if (hashIndex >= 0) { path = path.slice(hashIndex + 1) }