File: thebelab-helper.js

package info (click to toggle)
jupyter-sphinx 0.5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 300 kB
  • sloc: python: 1,576; makefile: 32; javascript: 18; sh: 13
file content (24 lines) | stat: -rw-r--r-- 864 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function initThebelab() {
    let activateButton = document.getElementById("thebelab-activate-button");
    if (activateButton.classList.contains('thebelab-active')) {
        return;
    }

    // Place all outputs below the source where this was not the case
    // to make them recognizable by thebelab
    let codeBelows = document.getElementsByClassName('thebelab-below');
    for(var i = 0; i < codeBelows.length; i++) {
        let prev = codeBelows[i]
        // Find previous sibling element, compatible with IE8
        do prev = prev.previousSibling; while(prev && prev.nodeType !== 1);
        swapSibling(prev, codeBelows[i])
    }

    thebelab.bootstrap();
    activateButton.classList.add('thebelab-active')
}

function swapSibling(node1, node2) {
    node1.parentNode.replaceChild(node1, node2);
    node1.parentNode.insertBefore(node2, node1);
}