Skip to content

Commit

Permalink
[toc2] Add backwards compatibility on export with pre-amd toc2.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbercher committed Jul 31, 2017
1 parent 466a78b commit 69b6431
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

var IPython;
var liveNotebook = false;

if (require.specified('base/js/namespace')) {
require(['base/js/namespace'], function(Jupyter_mod) {
liveNotebook = true;
IPython = Jupyter_mod;
});
}


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; }
Expand Down Expand Up @@ -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);
});
}
}
12 changes: 3 additions & 9 deletions src/jupyter_contrib_nbextensions/templates/toc2.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
</script>
Expand Down

0 comments on commit 69b6431

Please sign in to comment.