Sha256: c5ba4de9ab7d5b58245330d2a6a49fe1445d767fde4e3290a601b0fb4bdc232f

Contents?: true

Size: 1.51 KB

Versions: 271

Compression:

Stored size: 1.51 KB

Contents

/* global table, dom */

/**
 * Determine if a `HTMLTableCellElement` is a column header, if so get the scope of the header
 * @method getScope
 * @memberof axe.commons.table
 * @instance
 * @param {HTMLTableCellElement} cell The table cell to test
 * @return {Boolean|String} Returns `false` if not a column header, or the scope of the column header element
 */
table.getScope = function(cell) {
	var scope = cell.getAttribute('scope');
	var role = cell.getAttribute('role');

	if (
		cell instanceof Element === false ||
		['TD', 'TH'].indexOf(cell.nodeName.toUpperCase()) === -1
	) {
		throw new TypeError('Expected TD or TH element');
	}

	if (role === 'columnheader') {
		return 'col';
	} else if (role === 'rowheader') {
		return 'row';
	} else if (scope === 'col' || scope === 'row') {
		return scope;
	} else if (cell.nodeName.toUpperCase() !== 'TH') {
		return false;
	}
	var tableGrid = table.toGrid(dom.findUp(cell, 'table'));
	var pos = table.getCellPosition(cell, tableGrid);

	// The element is in a row with all th elements, that makes it a column header
	var headerRow = tableGrid[pos.y].reduce((headerRow, cell) => {
		return headerRow && cell.nodeName.toUpperCase() === 'TH';
	}, true);

	if (headerRow) {
		return 'col';
	}

	// The element is in a column with all th elements, that makes it a row header
	var headerCol = tableGrid
		.map(col => col[pos.x])
		.reduce((headerCol, cell) => {
			return headerCol && cell && cell.nodeName.toUpperCase() === 'TH';
		}, true);

	if (headerCol) {
		return 'row';
	}
	return 'auto';
};

Version data entries

271 entries across 271 versions & 1 rubygems

Version Path
govuk_publishing_components-30.4.1 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-30.4.0 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-30.3.0 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-30.2.1 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-30.2.0 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-30.1.0 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-30.0.0 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-29.15.3 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-29.15.2 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-29.15.1 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-29.15.0 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-29.14.0 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-29.13.0 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-29.12.1 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-29.12.0 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-29.11.0 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-29.10.0 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-29.9.0 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-29.8.0 node_modules/axe-core/lib/commons/table/get-scope.js
govuk_publishing_components-29.7.0 node_modules/axe-core/lib/commons/table/get-scope.js