[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.
This commit is contained in:
Josh Barnes
2017-08-23 02:10:36 +01:00
parent fe69131b63
commit 7e2baf745a
@@ -684,3 +684,14 @@ var table_of_contents = function (cfg,st) {
toggle_toc: toggle_toc,
};
});
// export table_of_contents to global namespace for backwards compatibility
// Do export synchronously, so that it's defined as soon as this file is loaded
if (!require.specified('base/js/namespace')) {
window.table_of_contents = function (cfg, st) {
// use require to ensure the module is correctly loaded before the
// actual call is made
require(['nbextensions/toc2/toc2'], function (toc2) {
toc2.table_of_contents(cfg, st);
});
};
}