From 619231e32fa536c7156a3c5de68f41e05c6bd567 Mon Sep 17 00:00:00 2001 From: Adhityaa Chandrasekar Date: Sun, 17 Feb 2019 17:45:05 -0500 Subject: [PATCH] commento.js: add scroll into view based on hash --- frontend/js/commento.js | 14 ++++++++++++++ frontend/sass/commento.scss | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/frontend/js/commento.js b/frontend/js/commento.js index 7fdfd08..888c73d 100644 --- a/frontend/js/commento.js +++ b/frontend/js/commento.js @@ -1523,6 +1523,7 @@ attrSet(footer, "style", ""); nameWidthFix(); + loadHash(); } @@ -1570,6 +1571,19 @@ } + function loadHash() { + if (window.location.hash && window.location.hash.startsWith("#commento-")) { + var el = $(ID_CARD + window.location.hash.split("-")[1]); + if (el === null) { + return; + } + + classAdd(el, "highlighted"); + el.scrollIntoView(true); + } + } + + global.main = function(callback) { root = $(ID_ROOT); if (root === null) { diff --git a/frontend/sass/commento.scss b/frontend/sass/commento.scss index 3457f76..86bf54a 100644 --- a/frontend/sass/commento.scss +++ b/frontend/sass/commento.scss @@ -55,4 +55,8 @@ font-weight: 700; margin-top: 16px; } + + .commento-highlighted { + background: $yellow-0; + } }