jazzy.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. window.jazzy = {'docset': false}
  2. if (typeof window.dash != 'undefined') {
  3. document.documentElement.className += ' dash'
  4. window.jazzy.docset = true
  5. }
  6. if (navigator.userAgent.match(/xcode/i)) {
  7. document.documentElement.className += ' xcode'
  8. window.jazzy.docset = true
  9. }
  10. // On doc load, toggle the URL hash discussion if present
  11. $(document).ready(function() {
  12. if (!window.jazzy.docset) {
  13. var linkToHash = $('a[href="' + window.location.hash +'"]');
  14. linkToHash.trigger("click");
  15. }
  16. });
  17. // On token click, toggle its discussion and animate token.marginLeft
  18. $(".token").click(function(event) {
  19. if (window.jazzy.docset) {
  20. return;
  21. }
  22. var link = $(this);
  23. var animationDuration = 300;
  24. $content = link.parent().parent().next();
  25. $content.slideToggle(animationDuration);
  26. // Keeps the document from jumping to the hash.
  27. var href = $(this).attr('href');
  28. if (history.pushState) {
  29. history.pushState({}, '', href);
  30. } else {
  31. location.hash = href;
  32. }
  33. event.preventDefault();
  34. });
  35. // Dumb down quotes within code blocks that delimit strings instead of quotations
  36. // https://github.com/realm/jazzy/issues/714
  37. $("code q").replaceWith(function () {
  38. return ["\"", $(this).contents(), "\""];
  39. });