Skip to content

Commit 7883710

Browse files
Merge branch 'scaladoc-fixes' into scaladoc-fixes-part3 pt 2
2 parents d8786c1 + ad0b88e commit 7883710

File tree

1 file changed

+35
-4
lines changed
  • scaladoc/resources/dotty_res/scripts

1 file changed

+35
-4
lines changed

scaladoc/resources/dotty_res/scripts/ux.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,41 @@ function attachAllListeners() {
5353
}
5454
}
5555
}
56-
57-
$(".side-menu span").on("click", function () {
58-
$(this).parent().toggleClass("expanded");
59-
});
56+
$(".side-menu span").on("click", function () {
57+
$(this).parent().toggleClass("expanded");
58+
});
59+
document.querySelectorAll('a').forEach(el => {
60+
const href = el.href
61+
if (href === "") { return }
62+
const url = new URL(href)
63+
el.addEventListener('click', e => {
64+
if (url.href.replace("#", "") === window.location.href.replace("#", "")) { return }
65+
if (url.origin !== window.location.origin) { return }
66+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) { return }
67+
e.preventDefault()
68+
e.stopPropagation()
69+
$.get(href, function (data) {
70+
const html = $.parseHTML(data)
71+
const title = html.find(node => node.nodeName === "TITLE").innerText
72+
const bodyDiv = html.find(node => node.nodeName === "DIV")
73+
const { children } = document.body.firstChild
74+
if (window.history.state === null) {
75+
window.history.replaceState({
76+
leftColumn: children[3].innerHTML,
77+
mainDiv: children[6].innerHTML,
78+
title: document.title,
79+
}, '')
80+
}
81+
document.title = title
82+
const leftColumn = bodyDiv.children[3].innerHTML
83+
const mainDiv = bodyDiv.children[6].innerHTML
84+
window.history.pushState({ leftColumn, mainDiv, title }, '', href)
85+
children[3].innerHTML = leftColumn
86+
children[6].innerHTML = mainDiv
87+
attachAllListeners()
88+
})
89+
})
90+
})
6091

6192
document.querySelectorAll('a').forEach(el => {
6293
const href = el.href

0 commit comments

Comments
 (0)