get-cell-position.js 871 B

1234567891011121314151617181920212223242526272829303132
  1. import toGrid from './to-grid';
  2. import findUp from '../dom/find-up';
  3. import { memoize } from '../../core/utils';
  4. /**
  5. * Get the x, y coordinates of a table cell; normalized for rowspan and colspan
  6. * @method getCellPosition
  7. * @memberof axe.commons.table
  8. * @instance
  9. * @param {HTMLTableCellElement} cell The table cell of which to get the position
  10. * @return {Object} Object with `x` and `y` properties of the coordinates
  11. */
  12. function getCellPosition(cell, tableGrid) {
  13. var rowIndex, index;
  14. if (!tableGrid) {
  15. tableGrid = toGrid(findUp(cell, 'table'));
  16. }
  17. for (rowIndex = 0; rowIndex < tableGrid.length; rowIndex++) {
  18. if (tableGrid[rowIndex]) {
  19. index = tableGrid[rowIndex].indexOf(cell);
  20. if (index !== -1) {
  21. return {
  22. x: index,
  23. y: rowIndex
  24. };
  25. }
  26. }
  27. }
  28. }
  29. export default memoize(getCellPosition);