Skip to content

Commit 7e2baf7

Browse files
committed
[toc2] add backwards-compatibility for html exported with old versions of toc2
this is accomplished by defining a window.table_of_contents function synchronously in the first pass of the file, so that it can be called by subsequent scripts in a page.
1 parent fe69131 commit 7e2baf7

File tree

1 file changed

+11
-0
lines changed
  • src/jupyter_contrib_nbextensions/nbextensions/toc2

1 file changed

+11
-0
lines changed

src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,3 +684,14 @@ var table_of_contents = function (cfg,st) {
684684
toggle_toc: toggle_toc,
685685
};
686686
});
687+
// export table_of_contents to global namespace for backwards compatibility
688+
// Do export synchronously, so that it's defined as soon as this file is loaded
689+
if (!require.specified('base/js/namespace')) {
690+
window.table_of_contents = function (cfg, st) {
691+
// use require to ensure the module is correctly loaded before the
692+
// actual call is made
693+
require(['nbextensions/toc2/toc2'], function (toc2) {
694+
toc2.table_of_contents(cfg, st);
695+
});
696+
};
697+
}

0 commit comments

Comments
 (0)