From da24df810d212489f3eed94558b0ae5d9fdfc65d Mon Sep 17 00:00:00 2001 From: George Cushen Date: Tue, 2 Jul 2019 21:29:33 +0100 Subject: [PATCH] fix(js): Chinese TOC links not scrolling to ID on click Fix #1178 --- assets/js/academic.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/assets/js/academic.js b/assets/js/academic.js index f144a830..2eb5adcc 100644 --- a/assets/js/academic.js +++ b/assets/js/academic.js @@ -23,9 +23,10 @@ */ function scrollToAnchor(target) { // If `target` is undefined or HashChangeEvent object, set it to window's hash. - target = (typeof target === 'undefined' || typeof target === 'object') ? window.location.hash : target; - // Escape colons from IDs, such as those found in Markdown footnote links. - target = target.replace(/:/g, '\\:'); + // Decode the hash as browsers can encode non-ASCII characters (e.g. Chinese symbols). + target = (typeof target === 'undefined' || typeof target === 'object') ? decodeURIComponent(window.location.hash) : target; + // Escape special chars from IDs, such as colons found in Markdown footnote links. + target = '#' + $.escapeSelector(target.substring(1)); // Previously, `target = target.replace(/:/g, '\\:');` // If target element exists, scroll to it taking into account fixed navigation bar offset. if($(target).length) { @@ -35,6 +36,8 @@ }, 600, function () { $('body').removeClass('scrolling'); }); + }else{ + console.warn('Cannot scroll to '+target+'. ID not found!'); } }