| | |
| | |
| | |
| | var configureThebe = () => { |
| | |
| | console.log("[sphinx-thebe]: Loading thebe config..."); |
| | thebe_config = document.querySelector("script[type=\"text/x-thebe-config\"]"); |
| |
|
| | |
| | if (document.querySelectorAll("div.thebe-cell").length > 0) { |
| | return; |
| | } |
| |
|
| | |
| | document.querySelectorAll(".thebe-launch-button").forEach((button) => { |
| | button.innerHTML = ` |
| | <div class="spinner"> |
| | <div class="rect1"></div> |
| | <div class="rect2"></div> |
| | <div class="rect3"></div> |
| | <div class="rect4"></div> |
| | </div> |
| | <span class="loading-text"></span>`; |
| | }); |
| |
|
| | |
| | var thebeStatus; |
| | thebelab.on("status", function (evt, data) { |
| | console.log("Status changed:", data.status, data.message); |
| |
|
| | const button = document.querySelector(".thebe-launch-button "); |
| | button.classList.replace( |
| | `thebe-status-${thebeStatus}`, |
| | `thebe-status-${data.status}` |
| | ) |
| | button.querySelector(".loading-text") |
| | .innerHTML = ( |
| | `<span class='launch_msg'>Launching from mybinder.org: </span> |
| | <span class='status'>${data.status}</span>` |
| | ); |
| |
|
| | |
| | thebeStatus = data.status; |
| |
|
| | |
| | if (data.status === "ready") { |
| | var thebeInitCells = document.querySelectorAll( |
| | ".thebe-init, .tag_thebe-init" |
| | ); |
| | thebeInitCells.forEach((cell) => { |
| | console.log("Initializing Thebe with cell: " + cell.id); |
| | cell.querySelector(".thebelab-run-button").click(); |
| | }); |
| | } |
| | }); |
| | }; |
| |
|
| | |
| | |
| | |
| | var modifyDOMForThebe = () => { |
| | |
| | const codeCells = document.querySelectorAll(thebe_selector); |
| | codeCells.forEach((codeCell, index) => { |
| | const codeCellId = (index) => `codecell${index}`; |
| | codeCell.id = codeCellId(index); |
| | codeCellText = codeCell.querySelector(thebe_selector_input); |
| | codeCellOutput = codeCell.querySelector(thebe_selector_output); |
| |
|
| | |
| | dataLanguage = detectLanguage(kernelName); |
| |
|
| | |
| | if (codeCellText) { |
| | codeCellText.setAttribute("data-language", dataLanguage); |
| | codeCellText.setAttribute("data-executable", "true"); |
| |
|
| | |
| | if (codeCellOutput) { |
| | codeCellOutput.setAttribute("data-output", ""); |
| | codeCellText.insertAdjacentElement('afterend', codeCellOutput); |
| | } |
| | } |
| |
|
| | |
| | codeCell.querySelectorAll("button.copybtn").forEach((el) => { |
| | el.remove(); |
| | }); |
| | }); |
| | }; |
| |
|
| | var initThebe = () => { |
| | |
| | if (typeof thebelab === "undefined") { |
| | console.log("[sphinx-thebe]: Loading thebe from CDN..."); |
| | document.querySelector(".thebe-launch-button ").innerText = "Loading thebe from CDN..."; |
| |
|
| | const script = document.createElement("script"); |
| | script.src = `${THEBE_JS_URL}`; |
| | document.head.appendChild(script); |
| |
|
| | |
| | script.addEventListener("load", () => { |
| | console.log("[sphinx-thebe]: Finished loading thebe from CDN..."); |
| | configureThebe(); |
| | modifyDOMForThebe(); |
| | thebelab.bootstrap(); |
| | }); |
| | } else { |
| | console.log( |
| | "[sphinx-thebe]: thebe already loaded, not loading from CDN..." |
| | ); |
| | configureThebe(); |
| | modifyDOMForThebe(); |
| | thebelab.bootstrap(); |
| | } |
| | }; |
| |
|
| | |
| | var detectLanguage = (language) => { |
| | if (language.indexOf("python") > -1) { |
| | language = "python"; |
| | } else if (language === "ir") { |
| | language = "r"; |
| | } |
| | return language; |
| | }; |
| |
|