From 7e2baf745ac8abf552b98499bb89b7e8b41b5fcb Mon Sep 17 00:00:00 2001 From: Josh Barnes Date: Wed, 16 Aug 2017 13:38:05 +0100 Subject: [PATCH] [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. --- .../nbextensions/toc2/toc2.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js b/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js index d776aa7..84adaba 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js @@ -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); + }); + }; +}