slides.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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/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': "^---\n",
  78. 'data-separator-vertical': "^--\n",
  79. 'data-separator-notes': "^Note:",
  80. 'data-charset': "utf-8"
  81. });
  82. $('.slides').html(markdownReference);
  83. }
  84. function scrollToCurrentSlide() {
  85. var i = Reveal.getIndices();
  86. Reveal.slide(i.h, i.v, i.f);
  87. }
  88. function reloadMarkdown() {
  89. insertMarkdownReference();
  90. RevealMarkdown.initialize();
  91. highlightAnyCodeBlocks();
  92. scrollToCurrentSlide();
  93. }
  94. function externalLinksInNewWindow() {
  95. $(document.links).filter(function () {
  96. return this.hostname != window.location.hostname;
  97. }).attr('target', '_blank');
  98. }
  99. insertMarkdownReference();
  100. initializeReveal();
  101. function themesCtrl() {
  102. var defaultTheme = "black.css",
  103. currentTheme = localStorage.getItem('theme?') ||
  104. defaultTheme;
  105. function setTheme(theme) {
  106. cssEl = $("#theme");
  107. cssEl.attr("href", "/static/reveal.js/css/theme/" + theme);
  108. localStorage.setItem('theme?', theme);
  109. }
  110. setTheme(currentTheme);
  111. if (!isPreview()) {
  112. return
  113. }
  114. var availableThemes = [
  115. "black.css",
  116. "beige.css",
  117. "blood.css",
  118. "league.css",
  119. "moon.css",
  120. "night.css",
  121. "serif.css",
  122. "simple.css",
  123. "sky.css",
  124. "solarized.css",
  125. "white.css",
  126. ];
  127. themeEl = $("#themes");
  128. availableThemes.forEach(function (theme) {
  129. elem = $("<option value=" + theme + ">" + theme + "</option>");
  130. themeEl.append(elem);
  131. })
  132. themeEl.val(currentTheme);
  133. themeEl.change(function () {
  134. val = themeEl.val()
  135. setTheme(val);
  136. });
  137. themeEl.attr("hidden", false);
  138. }
  139. // Monkey patch Reveal so we can reload markdown through an
  140. // inter window message (using the reveal rpc api)
  141. // (yes, reveal has an rpc api!)
  142. // see save.js
  143. Reveal.reloadMarkdown = reloadMarkdown;