😎 Give your xaringan slides some style
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

34 lines
1004B

  1. // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020.
  2. document.addEventListener('DOMContentLoaded', function() {
  3. // Do nothing if AnchorJS is used
  4. if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) {
  5. return;
  6. }
  7. const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
  8. // Do nothing if sections are already anchored
  9. if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) {
  10. return null;
  11. }
  12. // Use section id when pandoc runs with --section-divs
  13. const section_id = function(x) {
  14. return ((x.classList.contains('section') || (x.tagName === 'SECTION'))
  15. ? x.id : '');
  16. };
  17. // Add anchors
  18. h.forEach(function(x) {
  19. const id = x.id || section_id(x.parentElement);
  20. if (id === '') {
  21. return null;
  22. }
  23. let anchor = document.createElement('a');
  24. anchor.href = '#' + id;
  25. anchor.classList = ['anchor-section'];
  26. x.classList.add('hasAnchor');
  27. x.appendChild(anchor);
  28. });
  29. });