Skip to content

Commit

Permalink
Merge pull request #994 from jfbercher/master
Browse files Browse the repository at this point in the history
[toc2] update for cells width and sidebar height
  • Loading branch information
jfbercher authored May 25, 2017
2 parents 1db51e2 + 521f86c commit af6c402
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ var make_link = function(h, num_lbl) {
}

function setNotebookWidth(cfg, st) {
//cfg.widenNotebook = false;
//cfg.widenNotebook = true;
if (cfg.sideBar) {
if ($('#toc-wrapper').is(':visible')) {
$('#notebook-container').css('margin-left', $('#toc-wrapper').width() + 30)
Expand All @@ -176,19 +176,28 @@ var make_link = function(h, num_lbl) {
$('#notebook-container').css('margin-left', 30);
$('#notebook-container').css('width', $('#notebook').width() - 30);
} else { // original width
$("#notebook-container").css({'width':"82%", 'margin-left':'auto'})
$("#notebook-container").css({'width':''})
}
}
} else {
if (cfg.widenNotebook) {
$('#notebook-container').css('margin-left', 30);
$('#notebook-container').css('width', $('#notebook').width() - 30);
} else { // original width
$("#notebook-container").css({'width':"82%", 'margin-left':'auto'})
$("#notebook-container").css({'width':''})
}
}
}

function setSideBarHeight(cfg, st) {
if (cfg.sideBar) {
var headerVisibleHeight = $('#header').is(':visible') ? $('#header').height() : 0
$('#toc-wrapper').css('top', liveNotebook ? headerVisibleHeight : 0)
$('#toc-wrapper').css('height', $('#site').height());
$('#toc').css('height', $('#toc-wrapper').height() - $('#toc-header').height())
}
}

var create_toc_div = function (cfg,st) {
var toc_wrapper = $('<div id="toc-wrapper"/>')
.append(
Expand Down Expand Up @@ -281,21 +290,8 @@ var make_link = function(h, num_lbl) {
// On header/menu/toolbar resize, resize the toc itself
// (if displayed as a sidebar)
if (liveNotebook) {
$([Jupyter.events]).on("resize-header.Page", function() {
if (cfg.sideBar) {
$('#toc-wrapper').css('top', liveNotebook ? $('#header').height() : 0)
$('#toc-wrapper').css('height', $('#site').height());
$('#toc').css('height', $('#toc-wrapper').height() - $('#toc-header').height())
}
});
$([Jupyter.events]).on("toggle-all-headers", function() {
if (cfg.sideBar) {
var headerVisibleHeight = $('#header').is(':visible') ? $('#header').height() : 0
$('#toc-wrapper').css('top', liveNotebook ? headerVisibleHeight : 0)
$('#toc-wrapper').css('height', $('#site').height());
$('#toc').css('height', $('#toc-wrapper').height() - $('#toc-header').height())
}
});
$([Jupyter.events]).on("resize-header.Page", function() {setSideBarHeight(cfg, st);});
$([Jupyter.events]).on("toggle-all-headers", function() {setSideBarHeight(cfg, st);});
}

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

Expand Down

0 comments on commit af6c402

Please sign in to comment.