Skip to content

Commit 58fe1c5

Browse files
committed
Escape jquery's "special" characters in element ids/hash
eg. "#fn:1" will fail to find the element with id="fn:1", needs to be escaped to "#fn\\:1" to work.
1 parent 4abcb22 commit 58fe1c5

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

jquery.smooth-scroll.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,15 @@ $.fn.extend({
8080
var link = this, $link = $(this),
8181
hostMatch = ((location.hostname === link.hostname) || !link.hostname),
8282
pathMatch = opts.scrollTarget || (filterPath(link.pathname) || locationPath) === locationPath,
83-
thisHash = link.hash,
83+
thisHash = escape_selector(link.hash),
8484
include = true;
8585

86-
8786
if ( !opts.scrollTarget && (!hostMatch || !pathMatch || !thisHash) ) {
8887
include = false;
8988
} else {
9089
var exclude = opts.exclude, elCounter = 0, el = exclude.length;
9190
while (include && elCounter < el) {
92-
if ($link.is(exclude[elCounter++])) {
91+
if ($link.is(escape_selector(exclude[elCounter++]))) {
9392
include = false;
9493
}
9594
}
@@ -183,4 +182,8 @@ function filterPath(string) {
183182
.replace(/\/$/,'');
184183
}
185184

185+
function escape_selector (str) {
186+
return str.replace(/(:|\.)/g,'\\$1');
187+
}
188+
186189
})(jQuery);

jquery.smooth-scroll.min.js

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)