Sha256: b4fae540b4e0cd80c07a26aba4579986da915c057097d851dd4c7ba0f2837fd7

Contents?: true

Size: 1.28 KB

Versions: 139

Compression:

Stored size: 1.28 KB

Contents

var cells = [];

for (
	var rowIndex = 0, rowLength = node.rows.length;
	rowIndex < rowLength;
	rowIndex++
) {
	var row = node.rows[rowIndex];
	for (
		var cellIndex = 0, cellLength = row.cells.length;
		cellIndex < cellLength;
		cellIndex++
	) {
		cells.push(row.cells[cellIndex]);
	}
}

var ids = cells.reduce(function(ids, cell) {
	if (cell.getAttribute('id')) {
		ids.push(cell.getAttribute('id'));
	}
	return ids;
}, []);

var badCells = cells.reduce(function(badCells, cell) {
	var isSelf, notOfTable;

	// Get a list all the values of the headers attribute
	var headers = (cell.getAttribute('headers') || '')
		.split(/\s/)
		.reduce(function(headers, header) {
			header = header.trim();
			if (header) {
				headers.push(header);
			}
			return headers;
		}, []);

	if (headers.length !== 0) {
		// Check if the cell's id is in this list
		if (cell.getAttribute('id')) {
			isSelf = headers.indexOf(cell.getAttribute('id').trim()) !== -1;
		}

		// Check if the headers are of cells inside the table
		notOfTable = headers.reduce(function(fail, header) {
			return fail || ids.indexOf(header) === -1;
		}, false);

		if (isSelf || notOfTable) {
			badCells.push(cell);
		}
	}
	return badCells;
}, []);

if (badCells.length > 0) {
	this.relatedNodes(badCells);
	return false;
} else {
	return true;
}

Version data entries

139 entries across 139 versions & 1 rubygems

Version Path
govuk_publishing_components-21.37.0 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.36.1 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.36.0 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.35.0 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.34.1 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.34.0 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.33.0 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.32.0 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.31.0 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.30.0 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.29.1 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.29.0 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.28.1 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.28.0 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.27.1 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.27.0 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.26.2 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.26.1 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.26.0 node_modules/axe-core/lib/checks/tables/td-headers-attr.js
govuk_publishing_components-21.25.0 node_modules/axe-core/lib/checks/tables/td-headers-attr.js