slides.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. ]
  64. });
  65. }
  66. function highlightAnyCodeBlocks() {
  67. $(document).ready(function() {
  68. $('pre code').each(function(i, block) {
  69. hljs.highlightBlock(block);
  70. });
  71. });
  72. }
  73. function insertMarkdownReference() {
  74. var markdownReference = $('<section/>', {
  75. 'data-markdown': "/slides.md",
  76. 'data-separator': "^-( *)-( *)-( *-*)*",
  77. 'data-separator-notes': "^Note:",
  78. 'data-charset': "utf-8"
  79. });
  80. $('.slides').html(markdownReference);
  81. }
  82. function scrollToCurrentSlide() {
  83. var i = Reveal.getIndices();
  84. Reveal.slide(i.h, i.v, i.f);
  85. }
  86. function reloadMarkdown() {
  87. insertMarkdownReference();
  88. RevealMarkdown.initialize();
  89. highlightAnyCodeBlocks();
  90. scrollToCurrentSlide();
  91. }
  92. function externalLinksInNewWindow() {
  93. $(document.links).filter(function() {
  94. return this.hostname != window.location.hostname;
  95. }).attr('target', '_blank');
  96. }
  97. insertMarkdownReference();
  98. initializeReveal();
  99. // Monkey patch Reveal so we can reload markdown through an
  100. // inter window message (using the reveal rpc api)
  101. // (yes, reveal has an rpc api!)
  102. // see save.js
  103. Reveal.reloadMarkdown = reloadMarkdown;