thebelab-cell-button.html 833 B

123456789101112131415161718192021222324252627
  1. {% if site.use_thebelab_button -%}
  2. <script>
  3. /**
  4. * Set up thebelab button for code blocks
  5. */
  6. const thebelabCellButton = id =>
  7. `<a id="thebelab-cell-button-${id}" class="btn thebebtn o-tooltip--left" data-tooltip="Interactive Mode">
  8. <img src="{{ site.images_url | relative_url }}/edit-button.svg" alt="Start thebelab interactive mode">
  9. </a>`
  10. const addThebelabButtonToCodeCells = () => {
  11. const codeCells = document.querySelectorAll('div.input_area > div.highlight:not(.output) pre')
  12. codeCells.forEach((codeCell, index) => {
  13. const id = codeCellId(index)
  14. codeCell.setAttribute('id', id)
  15. if (document.getElementById("thebelab-cell-button-" + id) == null) {
  16. codeCell.insertAdjacentHTML('afterend', thebelabCellButton(id));
  17. }
  18. })
  19. }
  20. initFunction(addThebelabButtonToCodeCells);
  21. </script>
  22. {% endif %}