06fec558ae6948f461a7abe896cf6badf25a49cb
1 var jQuery
= (typeof(window
) != 'undefined') ? window
.jQuery
: require('jquery');
3 // Sphinx theme nav state
18 nav
.enable = function (withStickyNav
) {
21 // TODO this can likely be removed once the theme javascript is broken
22 // out from the RTD assets. This just ensures old projects that are
23 // calling `enable()` get the sticky menu on by default. All other cals
24 // to `enable` should include an argument for enabling the sticky menu.
25 if (typeof(withStickyNav
) == 'undefined') {
30 // Only allow enabling nav logic once
34 self
.isRunning
= true;
39 self
.win
.on('hashchange', self
.reset
);
43 self
.win
.on('scroll', function () {
44 if (!self
.linkScroll
) {
45 if (!self
.winScroll
) {
46 self
.winScroll
= true;
47 requestAnimationFrame(function() { self
.onScroll(); });
54 self
.win
.on('resize', function () {
55 if (!self
.winResize
) {
56 self
.winResize
= true;
57 requestAnimationFrame(function() { self
.onResize(); });
66 // TODO remove this with a split in theme and Read the Docs JS logic as
67 // well, it's only here to support 0.3.0 installs of our theme.
68 nav
.enableSticky = function() {
72 nav
.init = function ($) {
73 var doc
= $(document
),
76 this.navBar
= $('div.wy-side-scroll:first');
79 // Set up javascript UX bits
81 // Shift nav in mobile when clicking the menu.
82 .on('click', "[data-toggle='wy-nav-top']", function() {
83 $("[data-toggle='wy-nav-shift']").toggleClass("shift");
84 $("[data-toggle='rst-versions']").toggleClass("shift");
87 // Nav menu link click operations
88 .on('click', ".wy-menu-vertical .current ul li a", function() {
90 // Close menu when you click a link.
91 $("[data-toggle='wy-nav-shift']").removeClass("shift");
92 $("[data-toggle='rst-versions']").toggleClass("shift");
93 // Handle dynamic display of l3 and l4 nav lists
94 self
.toggleCurrent(target
);
97 .on('click', "[data-toggle='rst-current-version']", function() {
98 $("[data-toggle='rst-versions']").toggleClass("shift-up");
101 // Make tables responsive
102 $("table.docutils:not(.field-list,.footnote,.citation)")
103 .wrap("<div class='wy-table-responsive'></div>");
105 // Add extra class to responsive tables that contain
106 // footnotes or citations so that we can target them for styling
107 $("table.docutils.footnote")
108 .wrap("<div class='wy-table-responsive footnote'></div>");
109 $("table.docutils.citation")
110 .wrap("<div class='wy-table-responsive citation'></div>");
112 // Add expand links to all parents of nested ul
113 $('.wy-menu-vertical ul').not('.simple').siblings('a').each(function () {
115 expand
= $('<span class="toctree-expand"></span>');
116 expand
.on('click', function (ev
) {
117 self
.toggleCurrent(link
);
118 ev
.stopPropagation();
121 link
.prepend(expand
);
125 nav
.reset = function () {
126 // Get anchor from URL and open up nested nav
127 var anchor
= encodeURI(window
.location
.hash
) || '#';
130 var vmenu
= $('.wy-menu-vertical');
131 var link
= vmenu
.find('[href="' + anchor
+ '"]');
132 if (link
.length
=== 0) {
133 // this link was not found in the sidebar.
134 // Find associated id element, then its closest section
135 // in the document and try with that one.
136 var id_elt
= $('.document [id="' + anchor
.substring(1) + '"]');
137 var closest_section
= id_elt
.closest('div.section');
138 link
= vmenu
.find('[href="#' + closest_section
.attr("id") + '"]');
139 if (link
.length
=== 0) {
140 // still not found in the sidebar. fall back to main section
141 link
= vmenu
.find('[href="#"]');
144 // If we found a matching link then reset current and re-apply
145 // otherwise retain the existing match
146 if (link
.length
> 0) {
147 $('.wy-menu-vertical .current').removeClass('current');
148 link
.addClass('current');
149 link
.closest('li.toctree-l1').addClass('current');
150 link
.closest('li.toctree-l1').parent().addClass('current');
151 link
.closest('li.toctree-l1').addClass('current');
152 link
.closest('li.toctree-l2').addClass('current');
153 link
.closest('li.toctree-l3').addClass('current');
154 link
.closest('li.toctree-l4').addClass('current');
155 link
[0].scrollIntoView();
159 console
.log("Error expanding nav for anchor", err
);
164 nav
.onScroll = function () {
165 this.winScroll
= false;
166 var newWinPosition
= this.win
.scrollTop(),
167 winBottom
= newWinPosition
+ this.winHeight
,
168 navPosition
= this.navBar
.scrollTop(),
169 newNavPosition
= navPosition
+ (newWinPosition
- this.winPosition
);
170 if (newWinPosition
< 0 || winBottom
> this.docHeight
) {
173 this.navBar
.scrollTop(newNavPosition
);
174 this.winPosition
= newWinPosition
;
177 nav
.onResize = function () {
178 this.winResize
= false;
179 this.winHeight
= this.win
.height();
180 this.docHeight
= $(document
).height();
183 nav
.hashChange = function () {
184 this.linkScroll
= true;
185 this.win
.one('hashchange', function () {
186 this.linkScroll
= false;
190 nav
.toggleCurrent = function (elem
) {
191 var parent_li
= elem
.closest('li');
192 parent_li
.siblings('li.current').removeClass('current');
193 parent_li
.siblings().find('li.current').removeClass('current');
194 parent_li
.find('> ul li.current').removeClass('current');
195 parent_li
.toggleClass('current');
201 _ThemeNav
= ThemeNav();
203 if (typeof(window
) != 'undefined') {
204 window
.SphinxRtdTheme
= {
205 Navigation
: _ThemeNav
,
206 // TODO remove this once static assets are split up between the theme
207 // and Read the Docs. For now, this patches 0.3.0 to be backwards
208 // compatible with a pre-0.3.0 layout.html
209 StickyNav
: _ThemeNav
,
214 // requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
215 // https://gist.github.com/paulirish/1579671
220 var vendors
= ['ms', 'moz', 'webkit', 'o'];
221 for(var x
= 0; x
< vendors
.length
&& !window
.requestAnimationFrame
; ++x
) {
222 window
.requestAnimationFrame
= window
[vendors
[x
]+'RequestAnimationFrame'];
223 window
.cancelAnimationFrame
= window
[vendors
[x
]+'CancelAnimationFrame']
224 || window
[vendors
[x
]+'CancelRequestAnimationFrame'];
227 if (!window
.requestAnimationFrame
)
228 window
.requestAnimationFrame = function(callback
, element
) {
229 var currTime
= new Date().getTime();
230 var timeToCall
= Math
.max(0, 16 - (currTime
- lastTime
));
231 var id
= window
.setTimeout(function() { callback(currTime
+ timeToCall
); },
233 lastTime
= currTime
+ timeToCall
;
237 if (!window
.cancelAnimationFrame
)
238 window
.cancelAnimationFrame = function(id
) {