javascript.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <!-- polyfill needed for IE11 and below -->
  2. <script type="text/javascript" src={{ "reveal-hugo/object-assign.js" | relURL }}></script>
  3. <!-- Printing and PDF exports -->
  4. <!-- use Hugo to create the right path for the print stylesheet, then conditionally include it -->
  5. {{- $reveal_location := $.Param "reveal_hugo.reveal_cdn" | default "reveal-js" -}}
  6. <a href="{{ printf "%s/css/print/" $reveal_location | relURL }}" id="print-location" style="display: none;"></a>
  7. <script type="text/javascript">
  8. var printLocationElement = document.getElementById('print-location');
  9. var link = document.createElement('link');
  10. link.rel = 'stylesheet';
  11. link.type = 'text/css';
  12. link.href = printLocationElement.href + (window.location.search.match(/print-pdf/gi) ? 'pdf.css' : 'paper.css');
  13. document.getElementsByTagName('head')[0].appendChild(link);
  14. </script>
  15. <!-- output Hugo parameters into JavaScript to be used when initializing Reveal.js -->
  16. <script type="application/json" id="reveal-hugo-site-params">{{ jsonify .Site.Params.reveal_hugo | safeJS }}</script>
  17. <script type="application/json" id="reveal-hugo-page-params">{{ jsonify .Page.Params.reveal_hugo | safeJS }}</script>
  18. <!-- load Reveal.js javascripts -->
  19. <script src="{{ printf "%s/js/reveal.js" $reveal_location | relURL }}"></script>
  20. <!-- load Reveal.js plugins -->
  21. <script type="text/javascript">
  22. // Hugo lowercases all params and Reveal.js needs camelcase
  23. // So params in Hugo must be stored in snakecase and we camelize them here
  24. function camelize(map) {
  25. if (map) {
  26. Object.keys(map).forEach(function(k) {
  27. newK = k.replace(/(\_\w)/g, function(m) { return m[1].toUpperCase() });
  28. if (newK != k) {
  29. map[newK] = map[k];
  30. delete map[k];
  31. }
  32. });
  33. }
  34. return map;
  35. }
  36. // pattern inspired by https://github.com/RealOrangeOne/hugo-theme-revealjs
  37. var revealHugoDefaults = { center: true, controls: true, history: true, progress: true, transition: "slide" };
  38. var revealHugoSiteParams = JSON.parse(document.getElementById('reveal-hugo-site-params').innerHTML);
  39. var revealHugoPageParams = JSON.parse(document.getElementById('reveal-hugo-page-params').innerHTML);
  40. // See all options - https://github.com/hakimel/reveal.js#configuration
  41. var options = Object.assign({},
  42. camelize(revealHugoDefaults),
  43. camelize(revealHugoSiteParams),
  44. camelize(revealHugoPageParams));
  45. Reveal.initialize(options);
  46. </script>
  47. <!-- load Reveal.js plugins after Reveal.js is initialized -->
  48. {{ if $.Param "reveal_hugo.load_default_plugins" | default true }}
  49. {{ $default_plugins := slice "plugin/markdown/marked.js" "plugin/markdown/markdown.js" "plugin/highlight/highlight.js" "plugin/zoom-js/zoom.js" }}
  50. {{ range $default_plugins }}
  51. <script type="text/javascript" src="{{ printf "%s/%s" $reveal_location . | relURL }}"></script>
  52. {{ end }}
  53. <!-- always use local version of the notes plugin since HTML file it requires isn't on CDN -->
  54. <script type="text/javascript" src="{{ "reveal-js/plugin/notes/notes.js" | relURL }}"></script>
  55. {{ end }}
  56. <!-- load custom plugins locally only (not CDN since many plugins won't exist there) -->
  57. {{ range $.Param "reveal_hugo.plugins" }}
  58. <script type="text/javascript" src="{{ . | relURL }}"></script>
  59. {{ end }}
  60. {{- $custom_js := $.Param "reveal_hugo.custom_js" -}}
  61. {{- if $custom_js -}}
  62. <script type="text/javascript" src="{{ $custom_js | relURL }}"></script>
  63. {{- end -}}