sourceCode.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. document.addEventListener('DOMContentLoaded', function() {
  2. var $tabSource = document.querySelector('#source-tab'),
  3. $tabInfo = document.querySelector('#info-tab'),
  4. $tabReadme = document.querySelector('#readme-tab'),
  5. $tabTemplate = document.querySelector('#templateData-tab'),
  6. $tabTree = document.querySelector('#tree-tab'),
  7. $tabExample = document.querySelector('#example-tab'),
  8. $prismPre = document.querySelector('pre.compodoc-sourcecode');
  9. if ($tabSource && $prismPre) {
  10. $prismCode = $prismPre.querySelector('code'),
  11. $content = document.querySelector('.content'),
  12. prismLinks = document.querySelectorAll('.link-to-prism')
  13. for (var i = 0; i < prismLinks.length; i++) {
  14. prismLinks[i].addEventListener('click', linkToPrism, false);
  15. }
  16. function linkToPrism(event) {
  17. var targetLine = event.target.getAttribute('data-line');
  18. event.preventDefault();
  19. $prismPre.setAttribute('data-line', targetLine);
  20. Prism.highlightElement($prismCode, function() {});
  21. $tabSource.click();
  22. setTimeout(function() {
  23. var $prismHighlightLine = document.querySelector('.line-highlight'),
  24. top = parseInt(getComputedStyle($prismHighlightLine)['top']);
  25. $content.scrollTop = top;
  26. }, 500);
  27. };
  28. window.onhashchange = function(event) {
  29. switch (window.location.hash) {
  30. case '':
  31. case '#info':
  32. $tabInfo.click();
  33. break;
  34. case '#readme':
  35. $tabReadme.click();
  36. break;
  37. case '#source':
  38. $tabSource.click();
  39. break;
  40. case '#template':
  41. $tabTemplate.click();
  42. break;
  43. case '#dom-tree':
  44. $tabTree.click();
  45. break;
  46. case '#example':
  47. $tabExample.click();
  48. break;
  49. }
  50. }
  51. }
  52. });