Add javascript comments to the dt-ids snippet
[rnaseq-cwl-training.git] / _includes / javascript.html
index 010ae4af13d0e3b8c1c10e36d5a91527e3e51bf0..93b51527320bef9e2e1acf64913779f88cfb5110 100644 (file)
@@ -1,3 +1,6 @@
+{% comment %}
+  Javascript used in lesson and workshop pages.
+{% endcomment %}
 <script src="{{ page.root }}/assets/js/jquery.min.js"></script>
 <script src="{{ page.root }}/assets/js/bootstrap.min.js"></script>
 <script src="{{ page.root }}/assets/js/lesson.js"></script>
@@ -9,3 +12,22 @@
   ga('create', 'UA-37305346-2', 'auto');
   ga('send', 'pageview');
 </script>
+<script>
+  // This snippet fixes a bug caused by Github's pages-gem using kramdown v1.11.1.
+  // In order for anchor links to point to the correct place in the glossary, they must have an id
+  // This snippet ensures every definition term has an id
+  // See https://github.com/swcarpentry/styles/pull/129
+  $('dt').each(function () {
+    if (!this.id) {
+      var id = $(this).text();
+      // If there's a ( in the name (e.g., "comma-separated values (CSV)") - just take everything up to the first (
+      var index = id.indexOf('(');
+      if (index > 0) {
+        id = id.substring(0, index);
+      }
+      // Strip leading and trailing whitespace, convert spaces to dashes and convert everything to lowercase
+      id = id.trim().replace(/ /g, '-').toLowerCase();
+      this.id = id;
+    }
+  });
+</script>