-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy patha_target_warning.ts
More file actions
90 lines (84 loc) · 4.12 KB
/
a_target_warning.ts
File metadata and controls
90 lines (84 loc) · 4.12 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
/******************************************************************************
Copyright:: 2022- IBM, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*****************************************************************************/
import { CommonUtil } from "../util/CommonUtil";
import { VisUtil } from "../util/VisUtil";
import { FragmentUtil } from "../../v2/checker/accessibility/util/fragment";
import { Rule, RuleResult, RuleContext, RulePotential, RulePass, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
export const a_target_warning: Rule = {
id: "a_target_warning",
context: "dom:a[target],dom:area[target],dom:base[target]",
refactor: {
"WCAG20_A_TargetAndText": {
"Pass_0": "pass",
"Potential_1": "potential_warn"
}
},
help: {
"en-US": {
"group": `a_target_warning.html`,
"pass": `a_target_warning.html`,
"potential_warn": `a_target_warning.html`
}
},
messages: {
"en-US": {
"group": "Users should be warned in advance if their input action will open a new window",
"pass": "The user is warned in advance that the input action opens a new window",
"potential_warn": "Inform the user when their input action will open a new window"
}
},
rulesets: [{
id: [ "IBM_Accessibility", "IBM_Accessibility_next", "WCAG_2_0", "WCAG_2_1", "WCAG_2_2"],
num: "3.2.2", // num: [ "2.4.4", "x.y.z" ] also allowed
level: eRulePolicy.RECOMMENDATION,
toolkitLevel: eToolkitLevel.LEVEL_THREE
}],
act: [],
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
// skip the rule if it's AT hidden and not tabbable
if (VisUtil.isNodeHiddenFromAT(ruleContext) && !CommonUtil.isTabbable(ruleContext)) return null;
const params = {
paramWinText: {
value: ["new window", "new tab"],
type: "array"
}
}
let tStr = ruleContext.getAttribute("target");
let passed = tStr == "_parent" || tStr == "_self" || tStr == "_top" || CommonUtil.getFrameByName(ruleContext,tStr) != null;
if (!passed) {
// Name is not part of this frameset – must have potential to create new window?
// See if a new window is mentioned
let textStr = CommonUtil.getInnerText(ruleContext);
if (ruleContext.hasAttribute("title"))
textStr += " " + ruleContext.getAttribute("title");
// Check aria-describedby for warning text
if (ruleContext.hasAttribute("aria-describedby")) {
let describedbyIds = ruleContext.getAttribute("aria-describedby").trim().split(/\s+/);
for (let id of describedbyIds) {
let referencedElem = FragmentUtil.getById(ruleContext, id);
if (referencedElem) {
let describedText = CommonUtil.getInnerText(referencedElem);
if (describedText && describedText.trim().length > 0) {
textStr += " " + describedText;
}
}
}
}
for (let i = 0; !passed && i < params.paramWinText.value.length; ++i)
if (textStr.indexOf(params.paramWinText.value[i]) != -1) passed = true;
}
return passed ? RulePass("pass") : RulePotential("potential_warn");
}
}