Skip to content

Commit af6c402

Browse files
authored
Merge pull request #994 from jfbercher/master
[toc2] update for cells width and sidebar height
2 parents 1db51e2 + 521f86c commit af6c402

File tree

1 file changed

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

1 file changed

+15
-18
lines changed

src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ var make_link = function(h, num_lbl) {
166166
}
167167

168168
function setNotebookWidth(cfg, st) {
169-
//cfg.widenNotebook = false;
169+
//cfg.widenNotebook = true;
170170
if (cfg.sideBar) {
171171
if ($('#toc-wrapper').is(':visible')) {
172172
$('#notebook-container').css('margin-left', $('#toc-wrapper').width() + 30)
@@ -176,19 +176,28 @@ var make_link = function(h, num_lbl) {
176176
$('#notebook-container').css('margin-left', 30);
177177
$('#notebook-container').css('width', $('#notebook').width() - 30);
178178
} else { // original width
179-
$("#notebook-container").css({'width':"82%", 'margin-left':'auto'})
179+
$("#notebook-container").css({'width':''})
180180
}
181181
}
182182
} else {
183183
if (cfg.widenNotebook) {
184184
$('#notebook-container').css('margin-left', 30);
185185
$('#notebook-container').css('width', $('#notebook').width() - 30);
186186
} else { // original width
187-
$("#notebook-container").css({'width':"82%", 'margin-left':'auto'})
187+
$("#notebook-container").css({'width':''})
188188
}
189189
}
190190
}
191191

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

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

0 commit comments

Comments
 (0)