17e81981d34afd50f502e28f65a7f8e377c0b54e
[pti/rtp.git] / docs / _build / html / _static / bootstrap-sphinx.js
1 (function ($) {
2   /**
3    * Patch TOC list.
4    *
5    * Will mutate the underlying span to have a correct ul for nav.
6    *
7    * @param $span: Span containing nested UL"s to mutate.
8    * @param minLevel: Starting level for nested lists. (1: global, 2: local).
9    */
10   var patchToc = function ($ul, minLevel) {
11     var findA,
12       patchTables,
13       $localLi;
14
15     // Find all a "internal" tags, traversing recursively.
16     findA = function ($elem, level) {
17       level = level || 0;
18       var $items = $elem.find("> li > a.internal, > ul, > li > ul");
19
20       // Iterate everything in order.
21       $items.each(function (index, item) {
22         var $item = $(item),
23           tag = item.tagName.toLowerCase(),
24           $childrenLi = $item.children("li"),
25           $parentLi = $($item.parent("li"), $item.parent().parent("li"));
26
27         // Add dropdowns if more children and above minimum level.
28         if (tag === "ul" && level >= minLevel && $childrenLi.length > 0) {
29           $parentLi
30             .addClass("dropdown-submenu")
31             .children("a").first().attr("tabindex", -1);
32
33           $item.addClass("dropdown-menu");
34         }
35
36         findA($item, level + 1);
37       });
38     };
39
40     findA($ul);
41   };
42
43   /**
44    * Patch all tables to remove ``docutils`` class and add Bootstrap base
45    * ``table`` class.
46    */
47   patchTables = function () {
48     $("table.docutils")
49       .removeClass("docutils")
50       .addClass("table")
51       .attr("border", 0);
52   };
53
54   $(window).load(function () {
55     /*
56      * Scroll the window to avoid the topnav bar
57      * https://github.com/twbs/bootstrap/issues/1768
58      */
59     if ($("#navbar.navbar-fixed-top").length > 0) {
60       var navHeight = $("#navbar").height(),
61         shiftWindow = function() { scrollBy(0, -navHeight - 10); };
62
63       if (location.hash) {
64         setTimeout(shiftWindow, 1);
65       }
66
67       window.addEventListener("hashchange", shiftWindow);
68     }
69   });
70
71   $(document).ready(function () {
72     // Add styling, structure to TOC"s.
73     $(".dropdown-menu").each(function () {
74       $(this).find("ul").each(function (index, item){
75         var $item = $(item);
76         $item.addClass("unstyled");
77       });
78     });
79
80     // Global TOC.
81     if ($("ul.globaltoc li").length) {
82       patchToc($("ul.globaltoc"), 1);
83     } else {
84       // Remove Global TOC.
85       $(".globaltoc-container").remove();
86     }
87
88     // Local TOC.
89     $(".bs-sidenav ul").addClass("nav nav-list");
90     $(".bs-sidenav > ul > li > a").addClass("nav-header");
91
92     
93     // back to top
94     setTimeout(function () {
95       var $sideBar = $(".bs-sidenav");
96       var $content = $(".content");
97
98       // Enlarge content if sidebar is larger.
99       if ($sideBar.outerHeight(true) > $content.outerHeight(true)) {
100         $content.css("min-height", $sideBar.outerHeight(true));
101       }
102
103       $sideBar
104         // Add affix.
105         .affix({
106           offset: {
107             top: function () {
108               var offsetTop      = $sideBar.offset().top;
109               var sideBarMargin  = parseInt($sideBar.css("margin-top"), 10);
110               var navOuterHeight = $("#navbar").outerHeight(true);
111
112               return (this.top = offsetTop - navOuterHeight);
113             },
114             bottom: function () {
115               return (this.bottom = $(".footer").outerHeight(true));
116             }
117           }
118         })
119         // Trigger to reset if page content is scrolled to bottom.
120         .trigger("scroll.bs.affix.data-api");
121     }, 0);
122     
123
124     // Local TOC.
125     patchToc($("ul.localtoc"), 2);
126
127     // Mutate sub-lists (for bs-2.3.0).
128     $(".dropdown-menu ul").not(".dropdown-menu").each(function () {
129       var $ul = $(this),
130         $parent = $ul.parent(),
131         tag = $parent[0].tagName.toLowerCase(),
132         $kids = $ul.children().detach();
133
134       // Replace list with items if submenu header.
135       if (tag === "ul") {
136         $ul.replaceWith($kids);
137       } else if (tag === "li") {
138         // Insert into previous list.
139         $parent.after($kids);
140         $ul.remove();
141       }
142     });
143
144     // Add divider in page TOC.
145     $localLi = $("ul.localtoc li");
146     if ($localLi.length > 2) {
147       $localLi.first().after("<li class=\"divider\"></li>");
148     }
149
150     // Patch tables.
151     patchTables();
152
153     // Add Note, Warning styles. (BS v2,3 compatible).
154     $(".admonition").addClass("alert alert-info")
155       .filter(".warning, .caution")
156         .removeClass("alert-info")
157         .addClass("alert-warning").end()
158       .filter(".error, .danger")
159         .removeClass("alert-info")
160         .addClass("alert-danger alert-error").end();
161
162     // Inline code styles to Bootstrap style.
163     $("tt.docutils.literal").not(".xref").each(function (i, e) {
164       // ignore references
165       if (!$(e).parent().hasClass("reference")) {
166         $(e).replaceWith(function () {
167           return $("<code />").html($(this).html());
168         });
169       }});
170
171     // Update sourcelink to remove outerdiv (fixes appearance in navbar).
172     var $srcLink = $(".nav #sourcelink");
173     $srcLink.parent().html($srcLink.html());
174   });
175 }(window.$jqTheme || window.jQuery));