summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWu Cheng-Han2016-09-18 16:28:07 +0800
committerWu Cheng-Han2016-09-18 16:28:07 +0800
commitb708a728739e96849f9882dfce6bae9fa0b2851b (patch)
treef029aa2dc016e3b858d0191445719debd4906aef
parentc22791610c341582be5e008bd0a72200ca385747 (diff)
Fix the element selector in smoothHashScroll might contain special characters and cause the Syntax error
-rw-r--r--public/js/extra.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/public/js/extra.js b/public/js/extra.js
index 714e2057..8fa99ce2 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -635,12 +635,15 @@ function smoothHashScroll() {
$element.on('click', function (e) {
// store hash
var hash = decodeURIComponent(this.hash);
- if ($(hash).length <= 0) return;
+ // escape special characters in jquery selector
+ var $hash = $(hash.replace(/(:|\.|\[|\]|,)/g, "\\$1"));
+ // return if no element been selected
+ if ($hash.length <= 0) return;
// prevent default anchor click behavior
e.preventDefault();
// animate
$('body, html').stop(true, true).animate({
- scrollTop: $(hash).offset().top
+ scrollTop: $hash.offset().top
}, 100, "linear", function () {
// when done, add hash to url
// (default click behaviour)