Skip to content

Commit e55d11d

Browse files
committed
[toc2] rework minimize button - don't show in sidebar
1 parent a1af9fd commit e55d11d

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

src/jupyter_contrib_nbextensions/nbextensions/toc2/main.css

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ padding-left: 20px;
115115
font-weight: bold;
116116
}
117117

118+
.sidebar-wrapper .hide-btn {
119+
display:none;
120+
}
121+
118122
#toc-wrapper .hide-btn:before {
119123
content: "\f147";
120124
}
@@ -128,11 +132,6 @@ padding-left: 20px;
128132
text-decoration: none;
129133
}
130134

131-
#toc-wrapper .number_sections-btn {
132-
font-size: 14px;
133-
font-family: monospace;
134-
}
135-
136135
/* on scroll style */
137136
.highlight_on_scroll {
138137
border-left: solid 4px blue;

src/jupyter_contrib_nbextensions/nbextensions/toc2/main.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ define([
5959
// add per-notebook settings into global config object
6060
$.extend(true, cfg, metadata_settings);
6161

62-
//.....................global variables....
63-
var st={}
64-
st.oldTocHeight = undefined
65-
6662
var read_config = function (cfg, callback) {
6763
IPython.notebook.config.loaded.then(function () {
6864
// config may be specified at system level or at document level.
@@ -118,7 +114,7 @@ define([
118114
// ----------------------------------------------------------------------
119115

120116
function toggleToc() {
121-
toggle_toc(cfg, st)
117+
toggle_toc(cfg)
122118
}
123119

124120
var toc_button = function() {
@@ -211,12 +207,12 @@ define([
211207
var toc_init = function() {
212208
// read configuration, then call toc
213209
cfg = read_config(cfg, function() {
214-
table_of_contents(cfg, st);
210+
table_of_contents(cfg);
215211
}); // called after config is stable
216212
// event: render toc for each markdown cell modification
217213
events.on("rendered.MarkdownCell",
218214
function(evt, data) {
219-
table_of_contents(cfg, st); // recompute the toc
215+
table_of_contents(cfg); // recompute the toc
220216
rehighlight_running_cells() // re-highlight running cells
221217
highlight_toc_item(evt, data); // and of course the one currently rendered
222218
});

src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
// globally-used status variables:
1616
var rendering_toc_cell = false;
17+
var oldTocSize = {height: '200px', width: '200px'};
1718

1819
try {
1920
// this will work in a live notebook because nbextensions & custom.js
@@ -193,41 +194,41 @@
193194
}
194195
}
195196

197+
var makeUnmakeMinimized = function (cfg, animate) {
198+
var open = cfg.sideBar || cfg.toc_section_display;
199+
var new_css, wrap = $('#toc-wrapper');
200+
var anim_opts = {duration: animate ? 'fast' : 0};
201+
if (open) {
202+
$('#toc').show();
203+
new_css = cfg.sideBar ? {} : oldTocSize;
204+
}
205+
else {
206+
oldTocSize = wrap.css(['height', 'width']);
207+
new_css = {
208+
height: wrap.outerHeight() - wrap.find('#toc').outerHeight(),
209+
};
210+
anim_opts.complete = function () {
211+
$('#toc').hide();
212+
$('#toc-wrapper').css('width', '');
213+
};
214+
}
215+
wrap.toggleClass('closed', !open)
216+
.animate(new_css, anim_opts)
217+
.find('.hide-btn').attr('title', open ? 'Hide ToC' : 'Show ToC');
218+
return open;
219+
};
220+
196221
var create_toc_div = function(cfg, st) {
197222
var toc_wrapper = $('<div id="toc-wrapper"/>')
223+
.css('display', 'none')
198224
.append(
199225
$('<div id="toc-header"/>')
200226
.append('<span class="header"/>')
201227
.append(
202228
$('<i class="fa fa-fw hide-btn" title="Hide ToC">')
203229
.on('click', function (evt) {
204-
$('#toc').slideToggle({
205-
'complete': function() {
206-
if (liveNotebook) {
207-
IPython.notebook.metadata.toc['toc_section_display'] = $('#toc').css('display');
208-
IPython.notebook.set_dirty();
209-
}
210-
}
211-
});
212-
$('#toc-wrapper').toggleClass('closed');
213-
if ($('#toc-wrapper').hasClass('closed')) {
214-
st.oldTocHeight = $('#toc-wrapper').css('height');
215-
$('#toc-wrapper').css({
216-
height: 40
217-
});
218-
$('#toc-wrapper .hide-btn')
219-
.attr('title', 'Show ToC');
220-
} else {
221-
$('#toc-wrapper').css({
222-
height: st.oldTocHeight
223-
});
224-
$('#toc').css({
225-
height: st.oldTocHeight
226-
});
227-
$('#toc-wrapper .hide-btn')
228-
.attr('title', 'Hide ToC');
229-
}
230-
return false;
230+
cfg.toc_section_display = setMd('toc_section_display', !cfg.toc_section_display);
231+
makeUnmakeMinimized(cfg, true);
231232
})
232233
).append(
233234
$('<i class="fa fa-fw fa-refresh" title="Reload ToC">')
@@ -334,6 +335,10 @@
334335
},
335336
start: function(event, ui) {
336337
$(this).width($(this).width());
338+
if (!cfg.sideBar) {
339+
cfg.toc_section_display = setMd('toc_section_display', true);
340+
makeUnmakeMinimized(cfg);
341+
}
337342
},
338343
stop: function(event, ui) { // on save, store toc position
339344
if (liveNotebook) {

0 commit comments

Comments
 (0)