slides.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. function isPreview() {
  2. return !!window.location.search.match(/preview/gi);
  3. }
  4. function initializeReveal() {
  5. // Full list of configuration options available at:
  6. // https://github.com/hakimel/reveal.js#configuration
  7. Reveal.initialize({
  8. controls: true,
  9. progress: true,
  10. history: true,
  11. center: true,
  12. transition: 'slide', // none/fade/slide/convex/concave/zoom
  13. transitionSpeed: isPreview() ? 'fast' : 'default',
  14. embedded: isPreview() ? true : false,
  15. // Optional reveal.js plugins
  16. dependencies: [{
  17. src: '/static/reveal.js/lib/js/classList.js',
  18. condition: function() {
  19. return !document.body.classList;
  20. }
  21. },
  22. // Interpret Markdown in <section> elements
  23. {
  24. src: '/static/reveal.js/plugin/markdown/marked.js',
  25. condition: function() {
  26. return !!document.querySelector('[data-markdown]');
  27. }
  28. }, {
  29. src: '/static/reveal.js/plugin/markdown/markdown.js',
  30. condition: function() {
  31. return !!document.querySelector('[data-markdown]');
  32. }
  33. },
  34. // Syntax highlight for <code> elements
  35. {
  36. src: '/static/reveal.js/plugin/highlight/highlight.js',
  37. async: true,
  38. callback: function() {
  39. hljs.initHighlightingOnLoad();
  40. }
  41. },
  42. // Zoom in and out with Alt+click
  43. {
  44. src: '/static/reveal.js/plugin/zoom-js/zoom.js',
  45. async: true
  46. },
  47. // Speaker notes
  48. {
  49. src: '/static/reveal.js/plugin/notes/notes.js',
  50. async: true
  51. },
  52. // MathJax
  53. {
  54. src: '/static/reveal.js/plugin/math/math.js',
  55. async: true
  56. }
  57. {
  58. src: '/static/reveal.js/static/revealjs/lib/js/classList.js',
  59. condition: function() {
  60. return !document.body.classList;
  61. }
  62. }
  63. d
  64. ]
  65. });
  66. }
  67. function highlightAnyCodeBlocks() {
  68. $(document).ready(function() {
  69. $('pre code').each(function(i, block) {
  70. hljs.highlightBlock(block);
  71. });
  72. });
  73. }
  74. function insertMarkdownReference() {
  75. var markdownReference = $('<section/>', {
  76. 'data-markdown': "/slides.md",
  77. 'data-separator': "^-( *)-( *)-( *-*)*",
  78. 'data-separator-notes': "^Note:",
  79. 'data-charset': "utf-8"
  80. });
  81. $('.slides').html(markdownReference);
  82. }
  83. function scrollToCurrentSlide() {
  84. var i = Reveal.getIndices();
  85. Reveal.slide(i.h, i.v, i.f);
  86. }
  87. function reloadMarkdown() {
  88. insertMarkdownReference();
  89. RevealMarkdown.initialize();
  90. highlightAnyCodeBlocks();
  91. scrollToCurrentSlide();
  92. }
  93. function externalLinksInNewWindow() {
  94. $(document.links).filter(function() {
  95. return this.hostname != window.location.hostname;
  96. }).attr('target', '_blank');
  97. }
  98. insertMarkdownReference();
  99. initializeReveal();
  100. // Monkey patch Reveal so we can reload markdown through an
  101. // inter window message (using the reveal rpc api)
  102. // (yes, reveal has an rpc api!)
  103. // see save.js
  104. Reveal.reloadMarkdown = reloadMarkdown;