From 53a2bc8c8d4e38916d19fb4c57eea801ee35f913 Mon Sep 17 00:00:00 2001 From: ines Date: Tue, 12 Jun 2018 10:58:50 +0200 Subject: [PATCH] Only scroll sidebar item into view if needed [ci skip] --- website/_harp.json | 4 ++-- website/assets/js/main.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/website/_harp.json b/website/_harp.json index 335f3a131..106f039cf 100644 --- a/website/_harp.json +++ b/website/_harp.json @@ -84,8 +84,8 @@ } ], - "V_CSS": "2.2.0", - "V_JS": "2.2.0", + "V_CSS": "2.2.1", + "V_JS": "2.2.1", "DEFAULT_SYNTAX": "python", "ANALYTICS": "UA-58931649-1", "MAILCHIMP": { diff --git a/website/assets/js/main.js b/website/assets/js/main.js index 2ae1a4691..81eca8456 100644 --- a/website/assets/js/main.js +++ b/website/assets/js/main.js @@ -61,10 +61,10 @@ import initUniverse from './universe.vue.js'; const sidebarAttr = 'data-sidebar-active'; const sections = [...document.querySelectorAll(`[${navAttr}]`)]; const currentItem = document.querySelector(`[${sidebarAttr}]`); - if (currentItem && Element.prototype.scrollIntoView) { - currentItem.scrollIntoView(); - } if (window.inView) { + if (currentItem && Element.prototype.scrollIntoView && !inView.is(currentItem)) { + currentItem.scrollIntoView(); + } if (sections.length) { // highlight first item regardless sections[0].classList.add(activeClass); } @@ -74,7 +74,7 @@ import initUniverse from './universe.vue.js'; if (el) { sections.forEach(el => el.classList.remove(activeClass)); el.classList.add(activeClass); - if (Element.prototype.scrollIntoView) { + if (Element.prototype.scrollIntoView && !inView.is(el)) { el.scrollIntoView(); } }