-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShowImages_v2.0.js
More file actions
288 lines (228 loc) · 10.8 KB
/
ShowImages_v2.0.js
File metadata and controls
288 lines (228 loc) · 10.8 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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// Modified by Jane Norrie 2015.03.24, version 1 initial version (new page)
// Modified by Jane Norrie 2015.04.01, version 2 code cleanup
function start(myDocument) {
// Instead of window. for global
// we use aA. so that we don't have
// variables that might get mixed in
// with site-level js
//STANDARD ACROSS FAVELETS
var aA = [];
// VAR STANDARD ACROSS FAVELETS
// for id of added spans
// so we can removed them
aA.idi=0;
// keep track of alt tags for each frame
aA.frames = [];
// for frames outside domain
// so we can report them
aA.framemsg='';
aA.fi=0;
// STANDARD ACROSS FAVELETS & Recursive:
// checkFrames calls function that checks the page.
// Then, it calls itself for each doc in a frame
// It returns aA with all the aA.variables counted up
aA = checkFrames(myDocument, aA);
provideMessage(aA);
}
function checkFrames(myDocument,aA) {
//run showImageMaps check for current document which might
//have frames or images or both
aA = showImages(myDocument, aA);
//run checkFrames for each frame's document if there
//are any frames
var frametypes=new Array('frame','iframe','ilayer');
for (var x=0;x<frametypes.length;x++) {
var myframes=myDocument.getElementsByTagName(frametypes[x]);
for (var y=0;y<myframes.length;y++) {
try {
checkFrames(myframes[y].contentWindow.document,aA);
} catch(e) {
//errors are stored in aA too
console.log("Check frames error: " + e.message + ", frame.src: " + myframes[y].src);
aA.framemsg=aA.framemsg + '\n' + myframes[y].src;
aA.fi=aA.fi + 1;
}
}
}
return aA;
}
function provideMessage(aA) {
var y_pl = '';
var msg = '';
for (var i = 0; i < aA.frames.length; i++) {
if (aA.frames[i].y==1) {
y_pl='';
} else {
y_pl='s';
}
//alert("y=" + aA.frames[i].y);
if (aA.frames[i].y !== 0) {
if (i>0 && msg !== '') { msg += '\n\n'; }
msg += aA.frames[i].src + '\n' + aA.frames[i].y + ' image' + y_pl + ' without alt attributes!';
}
}
// standard
if (msg !== '') { alert(msg); }
}
function isBlank(s){
var E = /(\s)/;
var res = true;
for (var i = 0; i < s.length; i++) {
res=res && E.test(s.charAt(i));
}
return res;
}
function inArray(arr, obj) {
for(var i=0; i<arr.length; i++) {
if (arr[i] == obj) return true;
}
return false;
}
function showImages(mydocument, aA) {
var y = 0; // no alt
var w = 0; // valid alt tags
var wy = 0; // null alt
// Remove anything added last time favelet ran
// Create object just to check length of the properties array
var jt_generic_obj = mydocument.createElement("var");
var ie7 = false;
if (jt_generic_obj.attributes.length > 0) {
ie7 = true;
}
var myExpress1 = /hstAdded.*/;
var spanLive=mydocument.getElementsByTagName('span');
//static (span won't change - don't use spanLive while editing page)
var spans = [];
for (var z = 0; z < spanLive.length; z++) {
spans[z] = spanLive[z];
}
for (var s = 0;s < spans.length; s++) {
if (((ie7 && spans[s].attributes && spans[s].attributes.id.specified) ||
(!(ie7) && spans[s].hasAttribute('id'))) && myExpress1.test(spans[s].getAttribute('id'))) {
spans[s].parentNode.removeChild(spans[s]);
}
}
//create span with special id so we can remove it later
var pageAdd = mydocument.createElement('span');
pageAdd.id = "aistAdded" + (aA.idi++);
//give the span style that is common to all messages
pageAdd.style.fontSize = "x-small";
pageAdd.style.fontFamily = "arial,sans-serif";
pageAdd.style.fontWeight = "bold";
pageAdd.style.backgroundColor = "#FFFF00";
var img_els = mydocument.getElementsByTagName('img');
if (img_els.length > 0) {
for(var j = 0; j < img_els.length; j++) {
//create span with special id so we can remove it later
var pageAdd = mydocument.createElement('span');
pageAdd.id = "aistAdded" + (aA.idi++);
//give the span style that is common to all messages
pageAdd.style.fontSize="x-small";
pageAdd.style.fontFamily="arial,sans-serif";
pageAdd.style.fontWeight="bold";
pageAdd.style.backgroundColor="#FFFF00";
pageAdd.style.color="navy";
pageAdd.style.border="2px solid navy";
// create the span element for areas
var myArea = mydocument.createElement('span');
myArea.style.fontSize="x-small";
myArea.style.fontWeight="bold";
myArea.style.backgroundColor="#f5deb3";
if ((ie7 && img_els[j].attributes.alt.specified) || (!(ie7) && img_els[j].hasAttribute('alt'))) {
if (isBlank(img_els[j].alt)) {
// NULL ALT
thisArea=myArea.cloneNode(true);
thisArea.style.color="navy";
thisArea.appendChild(mydocument.createTextNode('alt=\"\"'));
pageAdd.appendChild(thisArea);
wy=wy+1;
} else {
// ALT
thisArea=myArea.cloneNode(true);
thisArea.style.color="navy";
thisArea.appendChild(mydocument.createTextNode('alt="' + img_els[j].alt + '"'));
pageAdd.appendChild(thisArea);
w=w+1;
}
// put a red border around the the image
img_els[j].style.padding='3px';
img_els[j].style.border='2px solid red';
}
else {
// NO ALT
thisArea=myArea.cloneNode(true);
thisArea.style.color="red";
thisArea.appendChild(mydocument.createTextNode('NO alt!'));
pageAdd.appendChild(thisArea);
y=y+1;
// put a red border around the the image
img_els[j].style.padding='3px';
img_els[j].style.border='2px solid red';
}
// identify title attributes
if ((ie7 && img_els[j].attributes.title.specified) || (!(ie7) && img_els[j].hasAttribute('title'))) {
thisArea=myArea.cloneNode(true);
thisArea.appendChild(mydocument.createTextNode(' title="' + img_els[j].title + '"'));
pageAdd.appendChild(thisArea);
}
// identify aria - taken from revealAria.js and modified slightly
if(img_els[j].attributes) {
for(var x = 0; x < img_els[j].attributes.length; x++) {
var myA = img_els[j].attributes[x].nodeName.toLowerCase();
var myExpress = /aria.*/;
if ((!ie7 || (ie7 && img_els[j].attributes[x].specified)) &&
((myExpress.test(myA) && img_els[j].getAttribute(myA)!==null) || (myA=="tabindex" && img_els[j].getAttribute(myA)=="-1") || (myA=="role" && img_els[j].getAttribute(myA)!==null))) {
thisArea=myArea.cloneNode(true);
thisArea.appendChild(mydocument.createTextNode(' ' + myA + '="' + img_els[j].getAttribute(myA) + '"'));
//check for items with ids
var value_is_id_attributes = new Array('aria-controls','aria-describedby','aria-flowto','aria-labelledby','aria-labeledby','aria-owns','aria-activedescendant');
// all can have a list of ids, except aria-activedescendant
if (inArray(value_is_id_attributes,myA)) {
//report on the attribute
//get array of ids
var id_array = img_els[j].getAttribute(myA).split(" ");
for (var mapi=0;mapi<id_array.length;mapi++) {
var myAid=id_array[mapi];
//alert(mydocument.getElementById(myAid));
if (mydocument.getElementById(myAid) !== undefined && mydocument.getElementById(myAid) !== null) {
//get object
var myIdTarget=mydocument.getElementById(myAid);
myIdTarget.style.border="2px dotted navy";
myIdTarget.style.backgroundColor="#ffffff";
//myTextNode2 = mydocument.createTextNode('<'+myIdTarget.tagName.toLowerCase()+' id="'+myAid+'">');
myTextNode2 = mydocument.createTextNode('id="'+myAid+'"');
//create message
var mySpan2 = mydocument.createElement('span');
mySpan2.setAttribute("id", ("ariastAddedid" + j));
//style message
mySpan2.style.color='navy';
mySpan2.style.fontSize="x-small";
mySpan2.style.fontWeight="bold";
mySpan2.style.backgroundColor="#ffff33";
mySpan2.style.border="1px solid #000000";
mySpan2.style.padding="2px";
mySpan2.style.marginRight="3px";
//append attribute info
mySpan2.appendChild(myTextNode2);
//place message for id's object
var firstthing = myIdTarget.childNodes[0];
if (firstthing === undefined) {firstthing = null;}
myIdTarget.insertBefore(mySpan2,firstthing);
} else {
thisArea.appendChild(mydocument.createTextNode(' [NO MATCH ID] '));
}
}
}
pageAdd.appendChild(thisArea);
}
}
}
//place item before image in question
img_els[j].parentNode.insertBefore(pageAdd, img_els[j]);
} // end for each img tag
} // end if img exists
var oFrame = {src:mydocument.location, y:y, w:w, wy:wy};
aA.frames.push(oFrame);
return aA;
} // end function
start(document);