Imported Upstream version 1.0.0
[platform/upstream/nghttp2.git] / doc / _themes / sphinx_rtd_theme / static / js / theme.js
1 function toggleCurrent (elem) {
2     var parent_li = elem.closest('li');
3     parent_li.siblings('li.current').removeClass('current');
4     parent_li.siblings().find('li.current').removeClass('current');
5     parent_li.find('> ul li.current').removeClass('current');
6     parent_li.toggleClass('current');
7 }
8
9 $(document).ready(function() {
10     // Shift nav in mobile when clicking the menu.
11     $(document).on('click', "[data-toggle='wy-nav-top']", function() {
12         $("[data-toggle='wy-nav-shift']").toggleClass("shift");
13         $("[data-toggle='rst-versions']").toggleClass("shift");
14     });
15     // Nav menu link click operations
16     $(document).on('click', ".wy-menu-vertical .current ul li a", function() {
17         var target = $(this);
18         // Close menu when you click a link.
19         $("[data-toggle='wy-nav-shift']").removeClass("shift");
20         $("[data-toggle='rst-versions']").toggleClass("shift");
21         // Handle dynamic display of l3 and l4 nav lists
22         toggleCurrent(target);
23         if (typeof(window.SphinxRtdTheme) != 'undefined') {
24             window.SphinxRtdTheme.StickyNav.hashChange();
25         }
26     });
27     $(document).on('click', "[data-toggle='rst-current-version']", function() {
28         $("[data-toggle='rst-versions']").toggleClass("shift-up");
29     });
30     // Make tables responsive
31     $("table.docutils:not(.field-list)").wrap("<div class='wy-table-responsive'></div>");
32
33     // Add expand links to all parents of nested ul
34     $('.wy-menu-vertical ul').siblings('a').each(function () {
35         var link = $(this);
36             expand = $('<span class="toctree-expand"></span>');
37         expand.on('click', function (ev) {
38             toggleCurrent(link);
39             ev.stopPropagation();
40             return false;
41         });
42         link.prepend(expand);
43     });
44 });
45
46 // Sphinx theme state
47 window.SphinxRtdTheme = (function (jquery) {
48     var stickyNav = (function () {
49         var navBar,
50             win,
51             winScroll = false,
52             linkScroll = false,
53             winPosition = 0,
54             enable = function () {
55                 init();
56                 reset();
57                 win.on('hashchange', reset);
58
59                 // Set scrolling
60                 win.on('scroll', function () {
61                     if (!linkScroll) {
62                         winScroll = true;
63                     }
64                 });
65                 setInterval(function () {
66                     if (winScroll) {
67                         winScroll = false;
68                         var newWinPosition = win.scrollTop(),
69                             navPosition = navBar.scrollTop(),
70                             newNavPosition = navPosition + (newWinPosition - winPosition);
71                         navBar.scrollTop(newNavPosition);
72                         winPosition = newWinPosition;
73                     }
74                 }, 25);
75             },
76             init = function () {
77                 navBar = jquery('nav.wy-nav-side:first');
78                 win = jquery(window);
79             },
80             reset = function () {
81                 // Get anchor from URL and open up nested nav
82                 var anchor = encodeURI(window.location.hash);
83                 if (anchor) {
84                     try {
85                         var link = $('.wy-menu-vertical')
86                             .find('[href="' + anchor + '"]');
87                         $('.wy-menu-vertical li.toctree-l1 li.current')
88                             .removeClass('current');
89                         link.closest('li.toctree-l2').addClass('current');
90                         link.closest('li.toctree-l3').addClass('current');
91                         link.closest('li.toctree-l4').addClass('current');
92                     }
93                     catch (err) {
94                         console.log("Error expanding nav for anchor", err);
95                     }
96                 }
97             },
98             hashChange = function () {
99                 linkScroll = true;
100                 win.one('hashchange', function () {
101                     linkScroll = false;
102                 });
103             };
104         jquery(init);
105         return {
106             enable: enable,
107             hashChange: hashChange
108         };
109     }());
110     return {
111         StickyNav: stickyNav
112     };
113 }($));