|
1 |
| -//--------------------------------------------------------------------- |
2 |
| - |
3 |
| -//......... utilitary functions............ |
4 |
| - |
5 |
| -var liveNotebook = !(typeof IPython == "undefined") |
6 |
| -var events; |
7 |
| -if (liveNotebook) { |
8 |
| - events = require('base/js/events'); |
9 |
| -} |
10 |
| -else { |
11 |
| - // in non-live notebook, there's no event structure, so we make our own |
12 |
| - if (window.events === undefined) { |
13 |
| - var Events = function () {}; |
14 |
| - window.events = $([new Events()]); |
| 1 | +(require.specified('base/js/namespace') ? define : function (deps, callback) { |
| 2 | + // if here, the Jupyter namespace hasn't been specified to be loaded. |
| 3 | + // This means that we're probably embedded in a page, so we need to make |
| 4 | + // our definition with a specific module name |
| 5 | + return define('nbextensions/toc2/toc2', deps, callback); |
| 6 | +})(['jquery', 'require'], function ($, require) { |
| 7 | + "use strict"; |
| 8 | + |
| 9 | + var IPython; |
| 10 | + var events; |
| 11 | + var liveNotebook = false; |
| 12 | + try { |
| 13 | + // this will work in a live notebook because nbextensions & custom.js |
| 14 | + // are loaded by/after notebook.js, which requires base/js/namespace |
| 15 | + IPython = require('base/js/namespace'); |
| 16 | + events = require('base/js/events'); |
| 17 | + liveNotebook = true; |
| 18 | + } |
| 19 | + catch (err) { |
| 20 | + // log the error, just in case we *are* in a live notebook |
| 21 | + console.log('[toc2] working in non-live notebook:', err); |
| 22 | + // in non-live notebook, there's no event structure, so we make our own |
| 23 | + if (window.events === undefined) { |
| 24 | + var Events = function () {}; |
| 25 | + window.events = $([new Events()]); |
| 26 | + } |
| 27 | + events = window.events; |
15 | 28 | }
|
16 |
| - events = window.events; |
17 |
| -} |
18 |
| - |
19 | 29 |
|
20 | 30 | function incr_lbl(ary, h_idx) { //increment heading label w/ h_idx (zero based)
|
21 | 31 | ary[h_idx]++;
|
@@ -695,3 +705,10 @@ var table_of_contents = function (cfg,st) {
|
695 | 705 | });
|
696 | 706 |
|
697 | 707 | };
|
| 708 | + |
| 709 | + return { |
| 710 | + highlight_toc_item: highlight_toc_item, |
| 711 | + table_of_contents: table_of_contents, |
| 712 | + toggle_toc: toggle_toc, |
| 713 | + }; |
| 714 | +}); |
0 commit comments