-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsourceCode.js
29 lines (24 loc) · 1.07 KB
/
sourceCode.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
document.addEventListener('DOMContentLoaded', function() {
var $tabSource = document.querySelector('#source-tab'),
$prismPre = document.querySelector('pre');
if ($prismPre) {
$prismCode = $prismPre.querySelector('code'),
$content = document.querySelector('.content'),
prismLinks = document.querySelectorAll('.link-to-prism')
for (var i = 0; i < prismLinks.length; i++) {
prismLinks[i].addEventListener('click', linkToPrism, false);
}
function linkToPrism(event) {
var targetLine = event.target.getAttribute('data-line');
event.preventDefault();
$prismPre.setAttribute('data-line', targetLine);
Prism.highlightElement($prismCode, function() {});
$tabSource.click();
setTimeout(function() {
var $prismHighlightLine = document.querySelector('.line-highlight'),
top = parseInt(getComputedStyle($prismHighlightLine)['top']);
$content.scrollTop = top;
}, 500);
};
}
});