Skip to content

Commit 58bd217

Browse files
committed
[toc2] simplify wrapper setup
by using existing functions
1 parent 22ac896 commit 58bd217

File tree

1 file changed

+20
-67
lines changed
  • src/jupyter_contrib_nbextensions/nbextensions/toc2

1 file changed

+20
-67
lines changed

src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js

Lines changed: 20 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -331,79 +331,32 @@
331331
})
332332

333333
// On header/menu/toolbar resize, resize the toc itself
334-
// (if displayed as a sidebar)
335334
$(window).on('resize', callbackPageResize);
336335
if (liveNotebook) {
337336
events.on("resize-header.Page toggle-all-headers", callbackPageResize);
338-
}
339-
340-
// restore toc position at load
341-
if (liveNotebook) {
342-
if (IPython.notebook.metadata.toc['toc_position'] !== undefined) {
343-
$('#toc-wrapper').css(IPython.notebook.metadata.toc['toc_position']);
337+
// restore toc position at load
338+
var toc_pos = IPython.notebook.metadata.toc.toc_position;
339+
if (toc_pos !== undefined) {
340+
toc_wrapper.css(cfg.sideBar ? {width: toc_pos.width} : toc_pos);
341+
oldTocSize.width = toc_pos.width;
342+
oldTocSize.height = toc_pos.height;
344343
}
345344
}
346-
// Ensure position is fixed
347-
$('#toc-wrapper').css('position', 'fixed');
348-
349-
// Restore toc display
350-
if (liveNotebook) {
351-
if (IPython.notebook.metadata.toc !== undefined) {
352-
if (IPython.notebook.metadata.toc['toc_section_display'] !== undefined) {
353-
$('#toc').css('display', IPython.notebook.metadata.toc['toc_section_display'])
354-
$('#toc').css('height', $('#toc-wrapper').height() - $('#toc-header').height())
355-
if (IPython.notebook.metadata.toc['toc_section_display'] == 'none') {
356-
$('#toc-wrapper').addClass('closed');
357-
$('#toc-wrapper').css({
358-
height: 40
359-
});
360-
$('#toc-wrapper .hide-btn')
361-
.text('[+]')
362-
.attr('title', 'Show ToC');
363-
}
364-
}
365-
if (IPython.notebook.metadata.toc['toc_window_display'] !== undefined) {
366-
console.log("******Restoring toc display");
367-
$('#toc-wrapper').css('display', IPython.notebook.metadata.toc['toc_window_display'] ? 'block' : 'none');
368-
}
369-
}
345+
else {
346+
// default to true for non-live notebook
347+
$.extend(true, cfg, {toc_window_display: true, toc_section_display: true});
370348
}
371-
372-
// if toc-wrapper is undefined (first run(?), then hide it)
373-
if ($('#toc-wrapper').css('display') == undefined) $('#toc-wrapper').css('display', "none");
374-
375-
$('#site').bind('siteHeight', function() {
376-
if (cfg.sideBar) $('#toc-wrapper').css('height', $('#site').height());
377-
})
378-
379-
$('#site').trigger('siteHeight');
380-
381-
// Initial style
382-
if (cfg.sideBar) {
383-
$('#toc-wrapper').addClass('sidebar-wrapper');
384-
if (!liveNotebook) {
385-
$('#toc-wrapper').css('width', '202px');
386-
$('#notebook-container').css('margin-left', '212px');
387-
$('#toc-wrapper').css('height', '96%');
388-
$('#toc').css('height', $('#toc-wrapper').height() - $('#toc-header').height())
389-
} else {
390-
if (cfg.toc_window_display) {
391-
setTimeout(function() {
392-
setNotebookWidth(cfg, st)
393-
}, 500)
394-
}
395-
setTimeout(function() {
396-
$('#toc-wrapper').css('height', $('#site').height());
397-
$('#toc').css('height', $('#toc-wrapper').height() - $('#toc-header').height())
398-
}, 500)
399-
}
400-
setTimeout(function() {
401-
$('#toc-wrapper').css('top', liveNotebook ? $('#header').height() : 0);
402-
}, 500) //wait a bit
403-
$('#toc-wrapper').css('left', 0);
404-
405-
} else {
406-
toc_wrapper.addClass('float-wrapper');
349+
// older toc2 versions stored string representations, so update those
350+
if (cfg.toc_window_display === 'none') {
351+
cfg.toc_window_display = setMd('toc_window_display', false);
352+
}
353+
if (cfg.toc_section_display === 'none') {
354+
cfg.toc_section_display = setMd('toc_section_display', false);
355+
}
356+
toc_wrapper.toggle(cfg.toc_window_display);
357+
makeUnmakeSidebar(cfg);
358+
if (!cfg.toc_section_display) {
359+
makeUnmakeMinimized(cfg);
407360
}
408361
};
409362

0 commit comments

Comments
 (0)