Skip to content

Commit 3245587

Browse files
committed
[toc2] Recompute sideBar height on window resize
1 parent 1dfafa6 commit 3245587

File tree

1 file changed

+12
-15
lines changed
  • src/jupyter_contrib_nbextensions/nbextensions/toc2

1 file changed

+12
-15
lines changed

src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ var make_link = function(h, num_lbl) {
190190
}
191191
}
192192

193+
function setSideBarHeight(cfg, st) {
194+
if (cfg.sideBar) {
195+
var headerVisibleHeight = $('#header').is(':visible') ? $('#header').height() : 0
196+
$('#toc-wrapper').css('top', liveNotebook ? headerVisibleHeight : 0)
197+
$('#toc-wrapper').css('height', $('#site').height());
198+
$('#toc').css('height', $('#toc-wrapper').height() - $('#toc-header').height())
199+
}
200+
}
201+
193202
var create_toc_div = function (cfg,st) {
194203
var toc_wrapper = $('<div id="toc-wrapper"/>')
195204
.append(
@@ -282,21 +291,8 @@ var make_link = function(h, num_lbl) {
282291
// On header/menu/toolbar resize, resize the toc itself
283292
// (if displayed as a sidebar)
284293
if (liveNotebook) {
285-
$([Jupyter.events]).on("resize-header.Page", function() {
286-
if (cfg.sideBar) {
287-
$('#toc-wrapper').css('top', liveNotebook ? $('#header').height() : 0)
288-
$('#toc-wrapper').css('height', $('#site').height());
289-
$('#toc').css('height', $('#toc-wrapper').height() - $('#toc-header').height())
290-
}
291-
});
292-
$([Jupyter.events]).on("toggle-all-headers", function() {
293-
if (cfg.sideBar) {
294-
var headerVisibleHeight = $('#header').is(':visible') ? $('#header').height() : 0
295-
$('#toc-wrapper').css('top', liveNotebook ? headerVisibleHeight : 0)
296-
$('#toc-wrapper').css('height', $('#site').height());
297-
$('#toc').css('height', $('#toc-wrapper').height() - $('#toc-header').height())
298-
}
299-
});
294+
$([Jupyter.events]).on("resize-header.Page", function() {setSideBarHeight(cfg, st);});
295+
$([Jupyter.events]).on("toggle-all-headers", function() {setSideBarHeight(cfg, st);});
300296
}
301297

302298
// enable dragging and save position on stop moving
@@ -637,6 +633,7 @@ var table_of_contents = function (cfg,st) {
637633
$(window).resize(function(){
638634
$('#toc').css({maxHeight: $(window).height() - 30});
639635
$('#toc-wrapper').css({maxHeight: $(window).height() - 10});
636+
setSideBarHeight(cfg, st),
640637
setNotebookWidth(cfg, st);
641638
});
642639

0 commit comments

Comments
 (0)