slides.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. themesCtrl();
  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. function themesCtrl() {
  101. var defaultTheme = "black.css",
  102. currentTheme = localStorage.getItem('theme?') ||
  103. defaultTheme;
  104. function setTheme(theme) {
  105. cssEl = $("#theme");
  106. cssEl.attr("href", "/static/reveal.js/css/theme/" + theme);
  107. localStorage.setItem('theme?', theme);
  108. }
  109. setTheme(currentTheme);
  110. if (!isPreview()) {
  111. return
  112. }
  113. var availableThemes = [
  114. "black.css",
  115. "beige.css",
  116. "blood.css",
  117. "league.css",
  118. "moon.css",
  119. "night.css",
  120. "serif.css",
  121. "simple.css",
  122. "sky.css",
  123. "solarized.css",
  124. "white.css",
  125. ];
  126. themeEl = $("#themes");
  127. availableThemes.forEach(function(theme) {
  128. elem = $("<option value=" + theme + ">" + theme + "</option>");
  129. themeEl.append(elem);
  130. })
  131. themeEl.val(currentTheme);
  132. themeEl.change(function() {
  133. val = themeEl.val()
  134. setTheme(val);
  135. });
  136. themeEl.attr("hidden", false);
  137. }
  138. // Monkey patch Reveal so we can reload markdown through an
  139. // inter window message (using the reveal rpc api)
  140. // (yes, reveal has an rpc api!)
  141. // see save.js
  142. Reveal.reloadMarkdown = reloadMarkdown;