diff --git a/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js b/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js index 2eed6aacf..f39a1e597 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js @@ -8,6 +8,7 @@ var IPython; var liveNotebook = false; + if (require.specified('base/js/namespace')) { require(['base/js/namespace'], function(Jupyter_mod) { liveNotebook = true; @@ -15,6 +16,7 @@ }); } + function incr_lbl(ary, h_idx) { //increment heading label w/ h_idx (zero based) ary[h_idx]++; for (var j = h_idx + 1; j < ary.length; j++) { ary[j] = 0; } @@ -678,3 +680,12 @@ var table_of_contents = function (cfg,st) { toggle_toc: toggle_toc, }; }); + +if (!liveNotebook) { + // export main function for backwards compatibility + function table_of_contents(cfg, st) { + return require(['nbextensions/toc2/toc2'], function(toc2) { + return toc2.table_of_contents(cfg, st); + }); + } +} \ No newline at end of file diff --git a/src/jupyter_contrib_nbextensions/templates/toc2.tpl b/src/jupyter_contrib_nbextensions/templates/toc2.tpl index cfdfb8796..7bf05c633 100644 --- a/src/jupyter_contrib_nbextensions/templates/toc2.tpl +++ b/src/jupyter_contrib_nbextensions/templates/toc2.tpl @@ -46,15 +46,9 @@ $( document ).ready(function(){ st.toc_index=0; // fire the main function with these parameters - - try { // new version of toc2 with amd module - require(['nbextensions/toc2/toc2'], function (toc2) { - toc2.table_of_contents(cfg, st); - }); - } - catch(e) { // for backward compatibility - table_of_contents(cfg, st); - } + require(['nbextensions/toc2/toc2'], function (toc2) { + toc2.table_of_contents(cfg, st); + }); });