Welcome to mirror list, hosted at ThFree Co, Russian Federation.

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