forked from whatwg/html
-
Notifications
You must be signed in to change notification settings - Fork 1
/
link-fixup.js
34 lines (29 loc) · 833 Bytes
/
link-fixup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(function () {
'use strict';
if (window.location.hash.length < 1) {
return;
}
var fragid = window.location.hash.substr(1);
if (fragid && document.getElementById(fragid)) {
return;
}
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
xhr.open('GET', '/multipage/fragment-links.json');
xhr.onload = function() {
var fragmentLinks = xhr.response;
// handle section-foo.html links from the old old multipage version,
// and broken foo.html from the new version
if (!fragid || !(fragid in fragmentLinks)) {
var m = window.location.pathname.match(/\/(?:section-)?([\w\-]+)\.html/);
if (m) {
fragid = m[1];
}
}
var page = fragmentLinks[fragid];
if (page) {
window.location.replace(page + '.html#' + fragid);
}
};
xhr.send();
})();