Skip to content

Commit f4cb633

Browse files
authored
Merge pull request #1250 from jfbercher/master
[toc2] Initialize toc2 button after cfg is loaded / fix #1249
2 parents 0a8f0a8 + 3f73c40 commit f4cb633

File tree

1 file changed

+6
-10
lines changed
  • src/jupyter_contrib_nbextensions/nbextensions/toc2

1 file changed

+6
-10
lines changed

src/jupyter_contrib_nbextensions/nbextensions/toc2/main.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ define([
1212
], function(
1313
requirejs,
1414
$,
15-
IPython,
15+
Jupyter,
1616
events,
1717
codecell,
1818
toc2
@@ -23,14 +23,14 @@ define([
2323
var highlight_toc_item = toc2.highlight_toc_item;
2424
var table_of_contents = toc2.table_of_contents;
2525
var toggle_toc = toc2.toggle_toc;
26+
var IPython = Jupyter;
2627

2728
// extra download as html with toc menu
2829
function addSaveAsWithToc() {
2930

3031
if (parseFloat(Jupyter.version.substr(0, 3)) >= 5.1) {
3132
if ($("#download_html_toc").length === 0) {
3233
/* Add an entry in the download menu */
33-
var dwm = $("#download_menu")
3434
var downloadEntry = $('<li id="download_html_toc"><a href="#">HTML with toc (.html)</a></li>')
3535
$("#download_html").after(downloadEntry)
3636
downloadEntry.click(function () {
@@ -137,11 +137,6 @@ define([
137137
};
138138
}
139139

140-
141-
function excute_codecell_callback(evt, data) {
142-
highlight_toc_item(evt, data);
143-
}
144-
145140
function rehighlight_running_cells() {
146141
$.each($('.running'), // re-highlight running cells
147142
function(idx, elt) {
@@ -158,6 +153,8 @@ define([
158153
var cfg = toc2.read_config();
159154
// create highlights style section in document
160155
create_additional_css(cfg);
156+
// add toc toggle button (now that cfg has loaded)
157+
toc_button(cfg);
161158
// call main function with newly loaded config
162159
table_of_contents(cfg);
163160
// event: render toc for each markdown cell modification
@@ -175,7 +172,7 @@ define([
175172
addSaveAsWithToc();
176173
})
177174

178-
// add a save as HTML with toc included
175+
// add a save as HTML with toc included
179176
addSaveAsWithToc();
180177
// Highlight cell on execution
181178
patch_CodeCell_get_callbacks()
@@ -184,11 +181,10 @@ define([
184181

185182
var load_ipython_extension = function() {
186183
load_css(); //console.log("Loading css")
187-
toc_button(); //console.log("Adding toc_button")
188184

189185
// Wait for the notebook to be fully loaded
190186
if (Jupyter.notebook !== undefined && Jupyter.notebook._fully_loaded) {
191-
// this tests if the notebook is fully loaded
187+
// this tests if the notebook is fully loaded
192188
console.log("[toc2] Notebook fully loaded -- toc2 initialized ")
193189
toc_init();
194190
} else {

0 commit comments

Comments
 (0)