Skip to content

Commit 8c736f8

Browse files
author
Luke Wright
committed
Merge pull request squizlabs#20 from lwright-sq/master
Add function to detect layout tables, and adjust SC 1.3.1 tests for them
2 parents 9b9c151 + bf8c64f commit 8c736f8

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

HTMLCS.js

+5
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,11 @@ var HTMLCS = new function()
635635
};
636636

637637
this.isLayoutTable = function(table) {
638+
var th = table.querySelector('th');
639+
if (th === null) {
640+
return true;
641+
}
642+
638643
return false;
639644
};
640645

Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_3/1_3_1.js

+37-8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ var HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = {
7575
break;
7676

7777
case 'table':
78+
this.testGeneralTable(element);
7879
this.testTableHeaders(element);
7980
this.testTableCaptionSummary(element);
8081
break;
@@ -676,20 +677,32 @@ var HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = {
676677
summary = summary.replace(/^\s*(.*?)\s*$/g, '$1');
677678

678679
if (summary !== '') {
679-
if (caption === summary) {
680-
HTMLCS.addMessage(HTMLCS.ERROR, table, 'If this table is a data table, and both a summary attribute and a caption element are present, the summary should not duplicate the caption.', 'H39,H73.4');
681-
}
680+
if (HTMLCS.util.isLayoutTable(table) === true) {
681+
HTMLCS.addMessage(HTMLCS.ERROR, table, 'This table appears to be used for layout, but contains a summary attribute. Layout tables must not contain summary attributes, or if supplied, must be empty.', 'H73.3.LayoutTable');
682+
} else {
683+
if (caption === summary) {
684+
HTMLCS.addMessage(HTMLCS.ERROR, table, 'If this table is a data table, and both a summary attribute and a caption element are present, the summary should not duplicate the caption.', 'H39,H73.4');
685+
}
682686

683-
HTMLCS.addMessage(HTMLCS.NOTICE, table, 'If this table is a data table, check that the summary attribute describes the table\'s organization or explains how to use the table.', 'H73.3.Check');
687+
HTMLCS.addMessage(HTMLCS.NOTICE, table, 'If this table is a data table, check that the summary attribute describes the table\'s organization or explains how to use the table.', 'H73.3.Check');
688+
}
684689
} else {
685-
HTMLCS.addMessage(HTMLCS.WARNING, table, 'If this table is a data table, consider using the summary attribute of the table element to give an overview of this table.', 'H73.3.NoSummary');
690+
if (HTMLCS.util.isLayoutTable(table) === false) {
691+
HTMLCS.addMessage(HTMLCS.WARNING, table, 'If this table is a data table, consider using the summary attribute of the table element to give an overview of this table.', 'H73.3.NoSummary');
692+
}
686693
}//end if
687694

688695
if (caption !== '') {
689-
HTMLCS.addMessage(HTMLCS.NOTICE, table, 'If this table is a data table, check that the caption element accurately describes this table.', 'H39.3.Check');
696+
if (HTMLCS.util.isLayoutTable(table) === true) {
697+
HTMLCS.addMessage(HTMLCS.ERROR, table, 'This table appears to be used for layout, but contains a caption element. Layout tables must not contain captions.', 'H39.3.LayoutTable');
698+
} else {
699+
HTMLCS.addMessage(HTMLCS.NOTICE, table, 'If this table is a data table, check that the caption element accurately describes this table.', 'H39.3.Check');
700+
}
690701
} else {
691-
HTMLCS.addMessage(HTMLCS.WARNING, table, 'If this table is a data table, consider using a caption element to the table element to identify this table.', 'H39.3.NoCaption');
692-
}
702+
if (HTMLCS.util.isLayoutTable(table) === false) {
703+
HTMLCS.addMessage(HTMLCS.WARNING, table, 'If this table is a data table, consider using a caption element to the table element to identify this table.', 'H39.3.NoCaption');
704+
}
705+
}//end if
693706
},
694707

695708
/**
@@ -900,5 +913,21 @@ var HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = {
900913
HTMLCS.addMessage(HTMLCS.WARNING, element, 'If this element contains a navigation section, it is recommended that it be marked up as a list.', 'H48');
901914
}
902915
}//end if
916+
},
917+
918+
/**
919+
* Provide generic messages for tables depending on what type of table they
920+
* are - layout or data.
921+
*
922+
* @param {DOMNode} table The table element to test.
923+
*
924+
* @returns void
925+
*/
926+
testGeneralTable: function(table) {
927+
if (HTMLCS.util.isLayoutTable(table) === true) {
928+
HTMLCS.addMessage(HTMLCS.NOTICE, table, 'This table appears to be a layout table. If it is meant to instead be a data table, ensure header cells are identified using th elements.', 'LayoutTable');
929+
} else {
930+
HTMLCS.addMessage(HTMLCS.NOTICE, table, 'This table appears to be a data table. If it is meant to instead be a layout table, ensure there are no th elements, and no summary or caption.', 'DataTable');
931+
}
903932
}
904933
};

0 commit comments

Comments
 (0)