forked from squizlabs/HTML_CodeSniffer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1_4_3.js
More file actions
94 lines (84 loc) · 4.37 KB
/
1_4_3.js
File metadata and controls
94 lines (84 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* +--------------------------------------------------------------------+
* | This HTML_CodeSniffer file is Copyright (c) |
* | Squiz Pty Ltd (ABN 77 084 670 600) |
* +--------------------------------------------------------------------+
* | IMPORTANT: Your use of this Software is subject to the terms of |
* | the Licence provided in the file licence.txt. If you cannot find |
* | this file please contact Squiz (www.squiz.com.au) so we may |
* | provide you a copy. |
* +--------------------------------------------------------------------+
*
*/
_global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_4_1_4_3 = {
/**
* Determines the elements to register for processing.
*
* Each element of the returned array can either be an element name, or "_top"
* which is the top element of the tested code.
*
* @returns {Array} The list of elements.
*/
register: function()
{
return ['_top'];
},
/**
* Process the registered element.
*
* @param {DOMNode} element The element registered.
* @param {DOMNode} top The top element of the tested code.
*/
process: function(element, top)
{
if (element === top) {
var failures = HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_4_1_4_3_Contrast.testContrastRatio(top, 4.5, 3.0);
for (var i = 0; i < failures.length; i++) {
var element = failures[i].element;
var decimals = 2;
var value = (Math.round(failures[i].value * Math.pow(10, decimals)) / Math.pow(10, decimals));
var required = failures[i].required;
var recommend = failures[i].recommendation;
var hasBgImg = failures[i].hasBgImage || false;
var bgColour = failures[i].bgColour || false;
var isAbsolute = failures[i].isAbsolute || false;
var hasAlpha = failures[i].hasAlpha || false;
// If the values would look identical, add decimals to the value.
while (required === value) {
decimals++;
value = (Math.round(failures[i].value * Math.pow(10, decimals)) / Math.pow(10, decimals));
}
if (required === 4.5) {
var code = 'G18';
} else if (required === 3.0) {
var code = 'G145';
}
var recommendText = [];
if (recommend) {
if (recommend.fore.from !== recommend.fore.to) {
recommendText.push(_global.HTMLCS.getTranslation("1_4_3_G18_or_G145.Fail.Recomendation.Text") + ' ' + recommend.fore.to);
}
if (recommend.back.from !== recommend.back.to) {
recommendText.push(_global.HTMLCS.getTranslation("1_4_3_G18_or_G145.Fail.Recomendation.Background") + ' ' + recommend.back.to);
}
}//end if
if (recommendText.length > 0) {
recommendText = ' ' + _global.HTMLCS.getTranslation("1_4_3_G18_or_G145.Fail.Recomendation") + ' ' + recommendText.join(', ') + '.';
}
if (isAbsolute === true) {
code += '.Abs';
HTMLCS.addMessage(HTMLCS.WARNING, element, _global.HTMLCS.getTranslation("1_4_3_G18_or_G145.Abs").replace(/\{\{required\}\}/g, required), code);
} else if (hasBgImg === true) {
code += '.BgImage';
HTMLCS.addMessage(HTMLCS.WARNING, element, _global.HTMLCS.getTranslation("1_4_3_G18_or_G145.BgImage").replace(/\{\{required\}\}/g, required), code);
} else if (hasAlpha === true) {
code += '.Alpha';
HTMLCS.addMessage(HTMLCS.WARNING, element, _global.HTMLCS.getTranslation("1_4_3_G18_or_G145.Alpha").replace(/\{\{required\}\}/g, required), code);
} else {
code += '.Fail';
HTMLCS.addMessage(HTMLCS.ERROR, element, _global.HTMLCS.getTranslation("1_4_3_G18_or_G145.Fail").replace(/\{\{required\}\}/g, required).replace(/\{\{value\}\}/g, value) + recommendText, code);
}//end if
}//end for
}//end if
}
};