Skip to content

Commit b56c1a9

Browse files
committed
Merge branch 'stefanruijsenaars-complex-headers'
2 parents fc81adb + 1000287 commit b56c1a9

File tree

11 files changed

+69
-6
lines changed

11 files changed

+69
-6
lines changed

HTMLCS.Util.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,8 @@ _global.HTMLCS.util = function() {
903903
* - wrongHeaders (Array): Array of elements where headers attr is incorrect.
904904
* Each is a structure with following keys: element,
905905
* expected [headers attr], actual [headers attr].
906+
* - isMultiLevelHeadersTable (Boolean): Whether this table has multi-level headers.
907+
* See: https://www.w3.org/WAI/tutorials/tables/multi-level/
906908
*
907909
* @param {DOMNode} element Table element to test upon.
908910
*
@@ -917,7 +919,8 @@ _global.HTMLCS.util = function() {
917919
allowScope: true,
918920
missingThId: [],
919921
missingTd: [],
920-
wrongHeaders: []
922+
wrongHeaders: [],
923+
isMultiLevelHeadersTable: false,
921924
};
922925

923926
var rows = self.getChildrenForTable(element, 'tr');
@@ -1022,6 +1025,7 @@ _global.HTMLCS.util = function() {
10221025

10231026
if ((multiHeaders.rows > 1) || (multiHeaders.cols > 1)) {
10241027
retval.allowScope = false;
1028+
retval.isMultiLevelHeadersTable = true;
10251029
} else if ((retval.allowScope === true) && ((multiHeaders.rows === 0) || (multiHeaders.cols === 0))) {
10261030
// If only one column OR one row header.
10271031
retval.required = false;

HTMLCS.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,15 @@ _global.HTMLCS = new function()
8484
var translations = _global.translation[this.lang];
8585

8686
if (!translations) {
87-
throw new Error ('Missing translations for language ' + this.lang);
87+
console.error('Missing translations for language ' + this.lang);
88+
return '';
8889
}
8990

9091
var translation = translations[text];
9192

9293
if (!translation) {
93-
throw new Error('Translation for "' + text + '" does not exist in current language ' + this.lang);
94+
console.error('Translation for "' + text + '" does not exist in current language ' + this.lang);
95+
return '';
9496
}
9597

9698
return translation;

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,13 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = {
459459
}
460460
}//end if
461461

462-
// Incorrect usage of headers - error; emit always.
463-
for (var i = 0; i < headersAttr.wrongHeaders.length; i++) {
464-
HTMLCS.addMessage(HTMLCS.ERROR, headersAttr.wrongHeaders[i].element, _global.HTMLCS.getTranslation("1_3_1_H43.IncorrectAttr").replace(/\{\{expected\}\}/g, headersAttr.wrongHeaders[i].expected).replace(/\{\{actual\}\}/g, headersAttr.wrongHeaders[i].actual), 'H43.IncorrectAttr');
462+
if (headersAttr.isMultiLevelHeadersTable) {
463+
HTMLCS.addMessage(HTMLCS.NOTICE, table, _global.HTMLCS.getTranslation("1_3_1_H43.IncorrectAttrNotice"), 'H43.IncorrectAttr');
464+
} else {
465+
// Incorrect usage of headers - error; emit always.
466+
for (var i = 0; i < headersAttr.wrongHeaders.length; i++) {
467+
HTMLCS.addMessage(HTMLCS.ERROR, headersAttr.wrongHeaders[i].element, _global.HTMLCS.getTranslation("1_3_1_H43.IncorrectAttr").replace(/\{\{expected\}\}/g, headersAttr.wrongHeaders[i].expected).replace(/\{\{actual\}\}/g, headersAttr.wrongHeaders[i].actual), 'H43.IncorrectAttr');
468+
}
465469
}
466470

467471
// Errors where headers are compulsory.

Tests/WCAG2/1_3_1_Table_Header_Attr.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Assert: No Error *.H43.MissingHeadersAttrs on #correctTableHeadersComplexRowspan
1414
Assert: No Error *.H63.1 on #correctTableHeadersComplexRowspan
1515
Assert: No Error *.H43,H63 on #correctTableHeadersComplexRowspan
16+
Assert: No Error *.H43.IncorrectAttr on #multiHeaders
1617
-->
1718
</head>
1819
<body>
@@ -108,5 +109,50 @@
108109
</tr>
109110
</tbody>
110111
</table>
112+
<table id="multiHeaders">
113+
<caption>
114+
Supplier contacts
115+
</caption>
116+
<tbody><tr>
117+
<th id="blank">&nbsp;</th>
118+
<th id="co1" headers="blank">Example 1 Ltd</th>
119+
<th id="co2" headers="blank">Example 2 Co</th>
120+
</tr>
121+
<tr>
122+
<th id="c1" headers="blank">Contact</th>
123+
<td headers="co1 c1">James Phillips</td>
124+
<td headers="co2 c1">Marie Beauchamp</td>
125+
</tr>
126+
<tr>
127+
<th id="p1" headers="blank">Position</th>
128+
<td headers="co1 p1">Sales Director</td>
129+
<td headers="co2 p1">Sales Manager</td>
130+
</tr>
131+
<tr>
132+
<th id="e1" headers="blank">Email</th>
133+
<td headers="co1 e1">jp@1ltd.example.com</td>
134+
<td headers="co2 e1">marie@2co.example.com</td>
135+
</tr>
136+
<tr>
137+
<th>&nbsp;</th>
138+
<th id="co3" headers="blank">Example 3 Ltd</th>
139+
<th id="co4" headers="blank">Example 4 Inc</th>
140+
</tr>
141+
<tr>
142+
<th id="c2" headers="blank">Contact</th>
143+
<td headers="co3 c2">Suzette Jones</td>
144+
<td headers="co4 c2">Alex Howe</td>
145+
</tr>
146+
<tr>
147+
<th id="p2" headers="blank">Position</th>
148+
<td headers="co3 p2">Sales Officer</td>
149+
<td headers="co4 p2">Sales Director</td>
150+
</tr>
151+
<tr>
152+
<th id="e2" headers="blank">Email</th>
153+
<td headers="co3 e2">Suz@ltd3.example.com</td>
154+
<td headers="co4 e2">howe@4inc.example.com</td>
155+
</tr>
156+
</tbody></table>
111157
</body>
112158
</html>

Translations/cn.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ _global.translation['cn'] = {
106106
,"1_3_1_H63.2" : 'td元素上作为其他元素标题的作用域属性在HTML5中已经过时了。使用th元素代替。'
107107
,"1_3_1_H43.ScopeAmbiguous" : '元素的作用域属性在具有多级标题的表中是不明确的。在td元素上使用headers属性。'
108108
,"1_3_1_H43.IncorrectAttr" : '此td元素上不正确的headers属性。期望的“{{expected}}”,但发现“{{actual}}”'
109+
,"1_3_1_H43.IncorrectAttrNotice" : 'Check that headers attribute on td element is correct.'
109110
,"1_3_1_H43.HeadersRequired" : 'td元素与其关联的th元素之间的关系没有定义。由于该表有多个层次的th元素,因此必须在td元素上使用headers属性。'
110111
,"1_3_1_H43.MissingHeaderIds" : '并非该表中的所有th元素都包含id属性。这些单元格应该包含id,以便td元素的header属性可以引用它们。'
111112
,"1_3_1_H43.MissingHeadersAttrs" : '并非此表中的所有td元素都包含header属性。每个headers属性应该列出与该单元格关联的所有th元素的id。'

Translations/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ _global.translation['en'] = {
121121
,"1_3_1_H63.2" : 'Scope attributes on td elements that act as headings for other elements are obsolete in HTML5. Use a th element instead.'
122122
,"1_3_1_H43.ScopeAmbiguous" : 'Scope attributes on th elements are ambiguous in a table with multiple levels of headings. Use the headers attribute on td elements instead.'
123123
,"1_3_1_H43.IncorrectAttr" : 'Incorrect headers attribute on this td element. Expected "{{expected}}" but found "{{actual}}"'
124+
,"1_3_1_H43.IncorrectAttrNotice" : 'Check that headers attribute on td elements are correct.'
124125

125126
,"1_3_1_H43.HeadersRequired" : 'The relationship between td elements and their associated th elements is not defined. As this table has multiple levels of th elements, you must use the headers attribute on td elements.'
126127
,"1_3_1_H43.MissingHeaderIds" : 'Not all th elements in this table contain an id attribute. These cells should contain ids so that they may be referenced by td elements\' headers attributes.'

Translations/fr.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ _global.translation['fr'] = {
120120
,"1_3_1_H63.2" : 'Les attributs Scope sur les éléments td qui servent de titres pour d\'autres éléments sont obsolètes dans HTML5. Utilisez un th élément à la place.'
121121
,"1_3_1_H43.ScopeAmbiguous" : 'Les attributs de portée sur ces éléments sont ambigus dans un tableau à niveaux multiples d\'en-têtes. Utilisez plutôt l\'attribut headers sur les éléments td.'
122122
,"1_3_1_H43.IncorrectAttr" : 'L\'attribut d\'en-tête incorrect sur cet élément td. Attendue "{{expected}}" mais trouvée "{{actual}}".'
123+
,"1_3_1_H43.IncorrectAttrNotice" : 'Check that headers attribute on td element is correct.'
123124

124125
,"1_3_1_H43.HeadersRequired" : 'La relation entre les éléments td et leurs éléments associés n\'est pas définie. Comme cette table a plusieurs niveaux de ces éléments, vous devez utiliser l\'attribut headers sur les éléments td.'
125126
,"1_3_1_H43.MissingHeaderIds" : 'Tous les éléments de cette table ne contiennent pas un attribut id. Ces cellules devraient contenir des ids de sorte qu\'elles puissent être référencées par des éléments td attributs d\'en-têtes.'

Translations/it.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ _global.translation['it'] = {
120120
,"1_3_1_H63.2" : 'Scope attributes on td elements that act as headings for other elements are obsolete in HTML5. Use a th element instead.'
121121
,"1_3_1_H43.ScopeAmbiguous" : 'Scope attributes on th elements are ambiguous in a table with multiple levels of headings. Use the headers attribute on td elements instead.'
122122
,"1_3_1_H43.IncorrectAttr" : 'Incorrect headers attribute on this td element. Expected "{{expected}}" but found "{{actual}}"'
123+
,"1_3_1_H43.IncorrectAttrNotice" : 'Check that headers attribute on td element is correct.'
123124

124125
,"1_3_1_H43.HeadersRequired" : 'The relationship between td elements and their associated th elements is not defined. As this table has multiple levels of th elements, you must use the headers attribute on td elements.'
125126
,"1_3_1_H43.MissingHeaderIds" : 'Not all th elements in this table contain an id attribute. These cells should contain ids so that they may be referenced by td elements\' headers attributes.'

Translations/ja.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ _global.translation['ja'] = {
120120
,"1_3_1_H63.2" : '他の要素の見出しとして機能する td 要素のスコープ属性は、HTML5では廃止されました。代わりに th 要素を使用してください。'
121121
,"1_3_1_H43.ScopeAmbiguous" : '複数のレベルの見出しを持つテーブルでは、 th 要素のスコープ属性はあいまいです。代わりに td 要素の headers 属性を使用してください。'
122122
,"1_3_1_H43.IncorrectAttr" : 'この td 要素のヘッダー属性が正しくありません。 "{{expected}}" を予期していましたが、 "{{actual}}" を検出しました'
123+
,"1_3_1_H43.IncorrectAttrNotice" : 'Check that headers attribute on td element is correct.'
123124

124125
,"1_3_1_H43.HeadersRequired" : 'td 要素とそれに関連する th 要素の関係は定義されていません。このテーブルには複数レベルの th 要素があるため、 td 要素には headers 属性を使用する必要があります。'
125126
,"1_3_1_H43.MissingHeaderIds" : 'このテーブルに id 属性を含まない th 要素があります。これらのセルは、それらが td 要素の headers 属性によって参照されるように ID を含むべきです。'

Translations/nl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ _global.translation['nl'] = {
120120
,"1_3_1_H63.2" : 'Scope attributen op td elementen die als hoofdingen gebruikt worden voor andere elementen zijn vervallen in HTML. Gebruik in plaats daarvan een th element.'
121121
,"1_3_1_H43.ScopeAmbiguous" : 'Scope attributen op th elementen zijn ambigu in een tabel met meerdere niveaus van hoofding. Gebruik in plaats daarvan het headers attribuut op td elementen.'
122122
,"1_3_1_H43.IncorrectAttr" : 'Foutief headers attribuut op dit td element. \"{{expected}}\" werd verwacht maar \"{{actual}}\" gevonden'
123+
,"1_3_1_H43.IncorrectAttrNotice" : 'Check that headers attribute on td element is correct.'
123124

124125
,"1_3_1_H43.HeadersRequired" : 'De relatie tussen td elementen en de eraan gebonden th elementen werd niet omschreven. Gezien deze tabel meerdere niveaus th elmenten bevat, moet het headers attribuut gebruikt worden op td elementen.'
125126
,"1_3_1_H43.MissingHeaderIds" : 'Niet alle th elementen in deze tabel hebben een id attribuut. Deze cellen zouden ids moeten bevatten zodat er kan naar verwezen worden in het headers attribuut van td elementen.'

0 commit comments

Comments
 (0)