5 * Will mutate the underlying span to have a correct ul for nav.
7 * @param $span: Span containing nested UL"s to mutate.
8 * @param minLevel: Starting level for nested lists. (1: global, 2: local).
10 var patchToc = function ($ul, minLevel) {
15 // Find all a "internal" tags, traversing recursively.
16 findA = function ($elem, level) {
18 var $items = $elem.find("> li > a.internal, > ul, > li > ul");
20 // Iterate everything in order.
21 $items.each(function (index, item) {
23 tag = item.tagName.toLowerCase(),
24 $childrenLi = $item.children("li"),
25 $parentLi = $($item.parent("li"), $item.parent().parent("li"));
27 // Add dropdowns if more children and above minimum level.
28 if (tag === "ul" && level >= minLevel && $childrenLi.length > 0) {
30 .addClass("dropdown-submenu")
31 .children("a").first().attr("tabindex", -1);
33 $item.addClass("dropdown-menu");
36 findA($item, level + 1);
44 * Patch all tables to remove ``docutils`` class and add Bootstrap base
47 patchTables = function () {
49 .removeClass("docutils")
54 $(window).load(function () {
56 * Scroll the window to avoid the topnav bar
57 * https://github.com/twbs/bootstrap/issues/1768
59 if ($("#navbar.navbar-fixed-top").length > 0) {
60 var navHeight = $("#navbar").height(),
61 shiftWindow = function() { scrollBy(0, -navHeight - 10); };
64 setTimeout(shiftWindow, 1);
67 window.addEventListener("hashchange", shiftWindow);
71 $(document).ready(function () {
72 // Add styling, structure to TOC"s.
73 $(".dropdown-menu").each(function () {
74 $(this).find("ul").each(function (index, item){
76 $item.addClass("unstyled");
81 if ($("ul.globaltoc li").length) {
82 patchToc($("ul.globaltoc"), 1);
85 $(".globaltoc-container").remove();
89 $(".bs-sidenav ul").addClass("nav nav-list");
90 $(".bs-sidenav > ul > li > a").addClass("nav-header");
94 setTimeout(function () {
95 var $sideBar = $(".bs-sidenav");
96 var $content = $(".content");
98 // Enlarge content if sidebar is larger.
99 if ($sideBar.outerHeight(true) > $content.outerHeight(true)) {
100 $content.css("min-height", $sideBar.outerHeight(true));
108 var offsetTop = $sideBar.offset().top;
109 var sideBarMargin = parseInt($sideBar.css("margin-top"), 10);
110 var navOuterHeight = $("#navbar").outerHeight(true);
112 return (this.top = offsetTop - navOuterHeight);
114 bottom: function () {
115 return (this.bottom = $(".footer").outerHeight(true));
119 // Trigger to reset if page content is scrolled to bottom.
120 .trigger("scroll.bs.affix.data-api");
125 patchToc($("ul.localtoc"), 2);
127 // Mutate sub-lists (for bs-2.3.0).
128 $(".dropdown-menu ul").not(".dropdown-menu").each(function () {
130 $parent = $ul.parent(),
131 tag = $parent[0].tagName.toLowerCase(),
132 $kids = $ul.children().detach();
134 // Replace list with items if submenu header.
136 $ul.replaceWith($kids);
137 } else if (tag === "li") {
138 // Insert into previous list.
139 $parent.after($kids);
144 // Add divider in page TOC.
145 $localLi = $("ul.localtoc li");
146 if ($localLi.length > 2) {
147 $localLi.first().after("<li class=\"divider\"></li>");
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();
162 // Inline code styles to Bootstrap style.
163 $("tt.docutils.literal").not(".xref").each(function (i, e) {
165 if (!$(e).parent().hasClass("reference")) {
166 $(e).replaceWith(function () {
167 return $("<code />").html($(this).html());
171 // Update sourcelink to remove outerdiv (fixes appearance in navbar).
172 var $srcLink = $(".nav #sourcelink");
173 $srcLink.parent().html($srcLink.html());
175 }(window.$jqTheme || window.jQuery));