File: toc-unfold.js

package info (click to toggle)
ttfautohint 1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,504 kB
  • ctags: 4,347
  • sloc: ansic: 38,386; sh: 5,749; cpp: 4,131; perl: 340; makefile: 309; sed: 39
file content (37 lines) | stat: -rw-r--r-- 858 bytes parent folder | download | duplicates (2)
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
/*!
 * toc-unfold.js
 *
 * JavaScript code to fold and unfold TOC entries
 *
 * written 2014 by Werner Lemberg
 */

// This code snippet needs `jquery' (http://code.jquery.com/jquery-1.11.2.js)

$(document).ready(function() {
  TOC.setup();
});

var TOC = {
  setup: function() {
    /* decorate TOC's `li' elements that have children with `folded' class */
    /* (pandoc doesn't do this) */
    $("#TOC li").each(function(i) {
      if ($(this).children().length) {
        $(this).addClass("folded");
      }
    });

    /* fold all entries */
    $(".folded").each(function(i) {
      $(this).children("ul:first").hide();
    });

    /* change class to `unfolded' if clicked */
    $(".folded").click(function(e) {
      $(this).toggleClass("unfolded");
      $(this).children("ul:first").slideToggle("300");
      e.stopPropagation();
    });  
  }
}