-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.html
255 lines (221 loc) · 10.8 KB
/
checker.html
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!DOCTYPE HTML>
<html>
<head>
<title>HTML Checker</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--[if lte IE 8]><script src="assets/js/ie/html5shiv.js"></script><![endif]-->
<link rel="stylesheet" href="assets/css/main.css" />
<!--[if lte IE 9]><link rel="stylesheet" href="assets/css/ie9.css" /><![endif]-->
<!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]-->
<script type="text/javascript">
function check() {
lineNumbers();
checkErrors();
return true;
};
function lineNumbers() {
var textAreaID = "code";
//turn the text area content into an array
var text = document.getElementById(textAreaID).value;
var content = text.split("\n");
var firstLine = content[0];
if (firstLine[0] == 1) {
return false;
}
//create array to hold new Content
var newContent = [];
//loop through and add line numbers
for (var i = 0; i < content.length; i++) { //begin for loop
//append the line numbers and the new value to the newContent array
newContent.push((i + 1) + "\t" + content[i] + "\n");
} //end for loop
//update the content of textArea with line numbers
document.getElementById("code").value = newContent.join("");
return true;
};
function checkErrors() {
var text = document.getElementById("code").value;
var content = text.split("\n");
var noAlt = "";
var titleNoAlt = "";
var emptyAlt = "";
var noHref = "";
var noLinkSection = "";
var anchorButton = "";
var textAction = "";
for (var i = 0; i < content.length; i++) {
//check for error img related errors
var oldLine = content[i];
var line = oldLine.replace(/\s/g,'');
var startIndex = line.search("<img");
if (startIndex !== -1) {
var endIndex = line.search(">");
var inside = line.substr(startIndex, endIndex - startIndex + 1);
var altIndex = inside.search("alt");
if(altIndex !== -1){
var emptyAltIndex = inside.search('alt=""');
if(emptyAltIndex !== -1){
//warning 3 empty alt
emptyAlt = emptyAlt + (i+1) + ", ";
}
var filledAltIndex = inside.search('alt="');
if(filledAltIndex === -1){
//warning 3 empty alt
emptyAlt = emptyAlt + (i+1) + ", ";
}
}else{
var titleIndex = inside.search("title");
if(titleIndex !== -1){
//warning 2 title without alt
titleNoAlt = titleNoAlt + (i+1) + ", ";
}else{
//warning 1 no alt
noAlt = noAlt + (i + 1) + ", ";
}
}
// look for alt
// if found, check for alt=""
// if found, warning 3 empty alt
// otherwise we're good, so do nothing
// if not found, check for title
// if found, warning 2 title but no alt
// if not found, warning 1 no alt
}
var actionWords = ["login", "signin", "me", "this", "here", "quit", "clickhere", "press", "try", "go", "home", "menu", "enter", "expand", "collapse", "edit", "signup"];
var actionFound = false;
for(var cnt = 0; cnt < actionWords.length; cnt++){
if( line.search(actionWords[cnt]) !== -1){
actionFound = true;
}
}
startIndex = line.search("<a");
if(startIndex !== -1){
var endIndex = line.search("</a>");
var inside = line.substr(startIndex, endIndex - startIndex + 1);
var classButtonIndex = inside.search('class="button"');
if(classButtonIndex !== -1){
//warning 6 anchor element of button class
anchorButton = anchorButton + (i+1) + ", ";
}
var hrefIndex = inside.search("href");
if( (actionFound === true)&&(hrefIndex === -1) ){
//no href but action oriented
//warning 4 nohref
noHref = noHref + (i+1) + ", ";
}
var poundIndex = inside.search("#");
if( poundIndex !== -1){
//warning 5 link to current page
noLinkSection = noLinkSection + (i+1) + ", ";
}
}
if(actionFound === true){
var textElement = false;
var pTag = line.search("<p") !== -1;
var hTag = line.search("<h") !== -1;
var iTag = line.search("<i") !== -1;
var bTag = line.search("<b") !== -1;
if( (pTag)||(hTag)||(iTag)||(bTag) ){
//warning 7 text with action oriented label
textAction = textAction + (i+1) + ", ";
}
}
}
//stripping the strings of their last commas
noAlt = noAlt.substr(0, noAlt.length-2);
titleNoAlt = titleNoAlt.substr(0, titleNoAlt.length-2);
emptyAlt = emptyAlt.substr(0, emptyAlt.length-2);
noHref = noHref.substr(0, noHref.length-2);
noLinkSection = noLinkSection.substr(0, noLinkSection.length-2);
anchorButton = anchorButton.substr(0, anchorButton.length-2);
textAction = textAction.substr(0, textAction.length-2);
document.getElementById('td1').innerHTML = noAlt;
document.getElementById('td2').innerHTML = titleNoAlt;
document.getElementById('td3').innerHTML = emptyAlt;
document.getElementById('td4').innerHTML = noHref;
document.getElementById('td5').innerHTML = noLinkSection;
document.getElementById('td6').innerHTML = anchorButton;
document.getElementById('td7').innerHTML = textAction;
}
</script>
</head>
<body>
<!-- Wrapper -->
<div id="wrapper">
<!-- Header -->
<header id="header">
<h1>HTML Checker</h1>
</header>
<!-- Nav -->
<nav id="nav">
<ul>
<li><a href="index.html">Home Page</a></li>
<li><a href="checker.html" class="active">HTML Checker</a></li>
<li><a href="info.html">Information</a></li>
</ul>
</nav>
<!-- Main -->
<div id="main">
<!-- Content -->
<section id="content" class="main">
<div style="height:100%">
<table style="float:right; width:45%; height: 100%; font-size: 16px">
<thead>
<tr>
<th>Error/Warning (click for more info)</th>
<th>Lines</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="info.html#noAlt">Image element does not have alt attribute</a></td>
<td id="td1"></td>
</tr>
<tr>
<td><a href="info.html#titleNoAlt">Image element has title attribute but not alt attribute</a></td>
<td id="td2"></td>
</tr>
<tr>
<td><a href="info.html#emptyAlt">Image element has empty alt attribute</a></td>
<td id="td3"></td>
</tr>
<tr>
<td><a href="info.html#noHref">Anchor element does not have href attribute but has action-oriented label</a></td>
<td id="td4"></td>
</tr>
<tr>
<td><a href="info.html#noLinkSection">Anchor element links to current page but not a separate section</a></td>
<td id="td5"></td>
</tr>
<tr>
<td><a href="info.html#anchorButton">Anchor element is of a button class</a></td>
<td id="td6"></td>
</tr>
<tr>
<td><a href="info.html#textAction">Text element has action-oriented label</a></td>
<td id="td7"></td>
</tr>
</tbody>
</table>
<div style="float:left; width:53%; height:100%">
<button onclick="check()" style="float:right; margin:auto; display:block; margin-bottom: 10px;">Check</button>
<p style="margin-top:5px">Paste your HTML in the box below, then press check!</p>
<textarea name="code" id="code" rows="12" style="float:center; height:100%; resize:none;" placeholder="Copy and paste your HTML code here"></textarea>
</div>
</div>
<!-- Footer -->
<footer id="footer">
<p class="copyright" style="margin-left: 5%;"> Develop Accessibility. Design: HTML5 UP.</p>
</footer>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/jquery.scrolly.min.js"></script>
<script src="assets/js/skel.min.js"></script>
<script src="assets/js/util.js"></script>
<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
<script src="assets/js/main.js"></script>
</body>
</html>