mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 03:33:58 -05:00
Fix the element selector in smoothHashScroll might contain special characters and cause the Syntax error
This commit is contained in:
parent
c22791610c
commit
b708a72873
1 changed files with 5 additions and 2 deletions
|
@ -635,12 +635,15 @@ function smoothHashScroll() {
|
||||||
$element.on('click', function (e) {
|
$element.on('click', function (e) {
|
||||||
// store hash
|
// store hash
|
||||||
var hash = decodeURIComponent(this.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
|
// prevent default anchor click behavior
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// animate
|
// animate
|
||||||
$('body, html').stop(true, true).animate({
|
$('body, html').stop(true, true).animate({
|
||||||
scrollTop: $(hash).offset().top
|
scrollTop: $hash.offset().top
|
||||||
}, 100, "linear", function () {
|
}, 100, "linear", function () {
|
||||||
// when done, add hash to url
|
// when done, add hash to url
|
||||||
// (default click behaviour)
|
// (default click behaviour)
|
||||||
|
|
Loading…
Reference in a new issue