slides.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/revealjs/lib/js/classList.js', condition: function() { return !document.body.classList; } },
  18. { src: '/static/revealjs/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
  19. { src: '/static/revealjs/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); }, callback: function() { externalLinksInNewWindow(); } },
  20. { src: '/static/revealjs/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
  21. { src: '/static/revealjs/plugin/zoom-js/zoom.js', async: true },
  22. { src: '/static/revealjs/plugin/notes/notes.js', async: true }
  23. ]
  24. });
  25. }
  26. function highlightAnyCodeBlocks() {
  27. $(document).ready(function() {
  28. $('pre code').each(function(i, block) {
  29. hljs.highlightBlock(block);
  30. });
  31. });
  32. }
  33. function insertMarkdownReference() {
  34. var markdownReference = $('<section/>', {
  35. 'data-markdown': "/slides.md",
  36. 'data-separator': "^-( *)-( *)-( *-*)*",
  37. 'data-separator-notes': "^Note:",
  38. 'data-charset': "utf-8"
  39. });
  40. $('.slides').html(markdownReference);
  41. }
  42. function scrollToCurrentSlide() {
  43. var i = Reveal.getIndices();
  44. Reveal.slide(i.h, i.v, i.f);
  45. }
  46. function reloadMarkdown() {
  47. insertMarkdownReference();
  48. RevealMarkdown.initialize();
  49. highlightAnyCodeBlocks();
  50. scrollToCurrentSlide();
  51. }
  52. function externalLinksInNewWindow() {
  53. $(document.links).filter(function() {
  54. return this.hostname != window.location.hostname;
  55. }).attr('target', '_blank');
  56. }
  57. insertMarkdownReference();
  58. initializeReveal();
  59. // Monkey patch Reveal so we can reload markdown through an
  60. // inter window message (using the reveal rpc api)
  61. // (yes, reveal has an rpc api!)
  62. // see save.js
  63. Reveal.reloadMarkdown = reloadMarkdown;