documentSelectors.js 964 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Select various elements on the page for later use
  3. */
  4. // IDs we'll attach to cells
  5. const codeCellId = index => `codecell${index}`
  6. const inputCellId = index => `inputcell${index}`
  7. pageElements = {}
  8. // All code cells
  9. findCodeCells = function() {
  10. var codeCells = document.querySelectorAll('div.c-textbook__content > div.highlighter-rouge > div.highlight > pre, div.input_area pre, div.text_cell_render div.highlight pre')
  11. pageElements['codeCells'] = codeCells;
  12. codeCells.forEach((codeCell, index) => {
  13. const id = codeCellId(index)
  14. codeCell.setAttribute('id', id)
  15. })
  16. };
  17. initFunction(findCodeCells);
  18. // All cells in general
  19. findInputCells = function() {
  20. var inputCells = document.querySelectorAll('div.jb_cell')
  21. pageElements['inputCells'] = inputCells;
  22. inputCells.forEach((inputCell, index) => {
  23. const id = inputCellId(index)
  24. inputCell.setAttribute('id', id)
  25. })
  26. };
  27. initFunction(findInputCells);