Skip to content

Commit 52b0d67

Browse files
authored
Merge pull request #10 from webmaster442/next
link fixing
2 parents 093b060 + ef64b75 commit 52b0d67

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

docs/script.js

+20-14
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@ if ('serviceWorker' in navigator) {
22
navigator.serviceWorker.register('serviceworker.js', { scope: '/ultimatedotnetcheatsheet/' });
33
}
44

5-
document.addEventListener("DOMContentLoaded", applyCopyButton);
5+
document.addEventListener("DOMContentLoaded", onLoaded);
66

7-
window.onscroll = function () { scrollFunction() };
7+
window.onscroll = function () {
8+
const scrollBtn = document.getElementById('navigate-top');
9+
if (document.body.scrollTop > 100
10+
|| document.documentElement.scrollTop > 100) {
11+
scrollBtn.style.display = 'block';
12+
}
13+
else {
14+
scrollBtn.style.display = 'none';
15+
}
16+
};
817

9-
function applyCopyButton() {
18+
function onLoaded() {
19+
//apply copy buttons
1020
const preElements = document.querySelectorAll('pre');
1121

1222
preElements.forEach(pre => {
@@ -20,10 +30,16 @@ function applyCopyButton() {
2030
navigator.clipboard.writeText(codeToCopy).then(() => {
2131
notify('Code copied to clipboard');
2232
}).catch(err => {
23-
notify('Failed to copy code: '+ err);
33+
notify('Failed to copy code: ' + err);
2434
});
2535
});
2636
});
37+
38+
//link fixing
39+
Array.from(document.links)
40+
.filter(link => link.hostname != window.location.hostname)
41+
.forEach(link => link.target = '_blank');
42+
2743
}
2844

2945
function notify(message) {
@@ -35,16 +51,6 @@ function notify(message) {
3551
}, 800);
3652
}
3753

38-
function scrollFunction() {
39-
const scrollBtn = document.getElementById('navigate-top');
40-
if (document.body.scrollTop > 100
41-
|| document.documentElement.scrollTop > 100) {
42-
scrollBtn.style.display = 'block';
43-
} else {
44-
scrollBtn.style.display = 'none';
45-
}
46-
}
47-
4854
function scrollToTop() {
4955
document.body.scrollTop = 0;
5056
document.documentElement.scrollTop = 0;

0 commit comments

Comments
 (0)