From b22033ac9bcdc12f348a304fb0b1e8aa7abf47a0 Mon Sep 17 00:00:00 2001 From: "D.A.Bashkirtsev" Date: Tue, 15 Jan 2019 17:52:05 +0500 Subject: [PATCH 1/3] Add scroll to page top on node click/collapse --- src/core/event/scroll.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/core/event/scroll.js b/src/core/event/scroll.js index 762d949f7..63b654ba2 100644 --- a/src/core/event/scroll.js +++ b/src/core/event/scroll.js @@ -15,7 +15,7 @@ function scrollTo(el) { enableScrollEvent = false scroller = new Tweezer({ start: window.pageYOffset, - end: el.getBoundingClientRect().top + window.pageYOffset, + end: el ? el.getBoundingClientRect().top + window.pageYOffset : 0, duration: 500 }) .on('tick', v => window.scrollTo(0, v)) @@ -123,19 +123,20 @@ export function scrollActiveSidebar(router) { }) } -export function scrollIntoView(path, id) { - if (!id) { - return - } +function scrollIntoView(path, id) { + var sidebar = getNode('.sidebar'); + var active = find(sidebar, 'li.active'); + active && active.classList.remove('active'); - const section = dom.find('#' + id) - section && scrollTo(section) + if (!id) { + scrollTo(null); + } else { + var section = find('#' + id); + section && scrollTo(section); - const li = nav[getNavKey(path, id)] - const sidebar = dom.getNode('.sidebar') - const active = dom.find(sidebar, 'li.active') - active && active.classList.remove('active') - li && li.classList.add('active') + var li = nav[getNavKey(path, id)]; + li && li.classList.add('active'); + } } const scrollEl = dom.$.scrollingElement || dom.$.documentElement From db866f37f599c195724729491c5b805a509fe020 Mon Sep 17 00:00:00 2001 From: "D.A.Bashkirtsev" Date: Tue, 15 Jan 2019 17:53:21 +0500 Subject: [PATCH 2/3] Return "export" keyword --- src/core/event/scroll.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/event/scroll.js b/src/core/event/scroll.js index 63b654ba2..35f2d8837 100644 --- a/src/core/event/scroll.js +++ b/src/core/event/scroll.js @@ -123,7 +123,7 @@ export function scrollActiveSidebar(router) { }) } -function scrollIntoView(path, id) { +export function scrollIntoView(path, id) { var sidebar = getNode('.sidebar'); var active = find(sidebar, 'li.active'); active && active.classList.remove('active'); From 8b8235da338369f599cfec27b764288df725cddd Mon Sep 17 00:00:00 2001 From: "D.A.Bashkirtsev" Date: Tue, 15 Jan 2019 17:56:36 +0500 Subject: [PATCH 3/3] Return "dom" --- src/core/event/scroll.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/event/scroll.js b/src/core/event/scroll.js index 35f2d8837..28e54daec 100644 --- a/src/core/event/scroll.js +++ b/src/core/event/scroll.js @@ -124,14 +124,14 @@ export function scrollActiveSidebar(router) { } export function scrollIntoView(path, id) { - var sidebar = getNode('.sidebar'); - var active = find(sidebar, 'li.active'); + var sidebar = dom.getNode('.sidebar'); + var active = dom.find(sidebar, 'li.active'); active && active.classList.remove('active'); if (!id) { scrollTo(null); } else { - var section = find('#' + id); + var section = dom.find('#' + id); section && scrollTo(section); var li = nav[getNavKey(path, id)];