Skip to content

Commit dd2c3e5

Browse files
committed
Make internal navigation handle <a>s in SVGs
1 parent ee0e347 commit dd2c3e5

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

assets/javascripts/lib/page.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,25 @@ var onclick = function (event) {
271271
}
272272

273273
let link = $.eventTarget(event);
274-
while (link && link.tagName !== "A") {
274+
while (link && !(link.tagName === "A" || link.tagName === "a")) {
275275
link = link.parentNode;
276276
}
277277

278-
if (link && !link.target && isSameOrigin(link.href)) {
278+
if (!link) return;
279+
280+
// If the `<a>` is in an SVG, its attributes are `SVGAnimatedString`s
281+
// instead of strings
282+
let href = link.href instanceof SVGAnimatedString
283+
? new URL(link.href.baseVal, location.href).href
284+
: link.href;
285+
let target = link.target instanceof SVGAnimatedString
286+
? link.target.baseVal
287+
: link.target;
288+
289+
if (!target && isSameOrigin(href)) {
279290
event.preventDefault();
280-
let path = link.pathname + link.search + link.hash;
291+
let parsedHref = new URL(href);
292+
let path = parsedHref.pathname + parsedHref.search + parsedHref.hash;
281293
path = path.replace(/^\/\/+/, "/"); // IE11 bug
282294
page.show(path);
283295
}

0 commit comments

Comments
 (0)