Skip to content

Commit a30d906

Browse files
committed
Handle positioning to a hash URL when the link is to an element within SVG output. Resolves remainder of issue #297.
1 parent b58c667 commit a30d906

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

MathJax.js

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

config/TeX-AMS-MML_SVG-full.js

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

jax/output/SVG/jax.js

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

unpacked/MathJax.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if (!window.MathJax) {window.MathJax= {}}
3030
if (!MathJax.Hub) { // skip if already loaded
3131

3232
MathJax.version = "2.0";
33-
MathJax.fileversion = "2.0.5";
33+
MathJax.fileversion = "2.0.6";
3434

3535
/**********************************************************/
3636

@@ -1923,8 +1923,21 @@ MathJax.Hub.Startup = {
19231923
for (var i = 0, m = a.length; i < m; i++)
19241924
{if (a[i].name === name) {target = a[i]; break}}
19251925
}
1926-
if (target) {setTimeout(function () {target.scrollIntoView(true)},1)}
1926+
if (target) {
1927+
while (!target.scrollIntoView) {target = target.parentNode}
1928+
target = this.HashCheck(target);
1929+
if (target && target.scrollIntoView)
1930+
{setTimeout(function () {target.scrollIntoView(true)},1)}
1931+
}
1932+
}
1933+
},
1934+
HashCheck: function (target) {
1935+
if (target.isMathJax) {
1936+
var jax = MathJax.Hub.getJaxFor(target);
1937+
if (jax && MathJax.OutputJax[jax.outputJax].hashCheck)
1938+
{target = MathJax.OutputJax[jax.outputJax].hashCheck(target)}
19271939
}
1940+
return target;
19281941
},
19291942

19301943
//

unpacked/jax/output/SVG/jax.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@
345345
state.SVGlast = state.SVGeqn;
346346
},
347347

348+
//
349+
// Return the containing HTML element rather than the SVG element, since
350+
// most browsers can't position to an SVG element properly.
351+
//
352+
hashCheck: function (target) {
353+
if (target && target.nodeName === "g")
354+
{do {target = target.parentNode} while (target && target.firstChild.nodeName !== "svg")}
355+
return target;
356+
},
357+
348358
getJaxFromMath: function (math) {
349359
if (math.parentNode.className === "MathJax_SVG_Display") {math = math.parentNode}
350360
return HUB.getJaxFor(math.nextSibling);
@@ -1035,12 +1045,9 @@
10351045
SVGlink: function () {
10361046
var href = this.href.animVal;
10371047
if (href.charAt(0) === "#") {
1038-
var link = document.getElementById(href.substr(1));
1039-
if (link && link.nodeName === "g") {
1040-
do {link = link.parentNode} while (link && link.nodeName !== "svg");
1041-
if (link && link.parentNode && link.parentNode.scrollIntoView)
1042-
{setTimeout(function () {link.parentNode.scrollIntoView(true)},1)}
1043-
}
1048+
var target = SVG.hashCheck(document.getElementById(href.substr(1)));
1049+
if (target && target.scrollIntoView)
1050+
{setTimeout(function () {target.parentNode.scrollIntoView(true)},1)}
10441051
}
10451052
document.location = href;
10461053
},

0 commit comments

Comments
 (0)