-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFrames.js
More file actions
394 lines (273 loc) · 12.6 KB
/
Frames.js
File metadata and controls
394 lines (273 loc) · 12.6 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
function startFrames(){
//Instead of window. for global
// we use aA. so that we don't have
// variables that might get mixed in
// with site-level js
//aA holds all variable that are global
// throughout frames
//STANDARD ACROSS FAVELETS
var aA=[];
//VAR SPECIFIC TO THIS FAVELET
aA.f=0; //num frames
aA.ff=0; //num iframes
aA.ef=0; //num frames with errors
aA.eff=0; //num iframes with errors
aA.tiny=0; //num tiny frames
// to save html nodes for
// printing to results page
aA.infoTree=document.createElement('div');
//VAR STANDARD ACROSS FAVELETS
// for id of added spans
// so we can removed them
aA.idi=0;
// 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 = checkFramesFrames(document,aA,aA.infoTree);
//STANDARD - reporting once done recursing through frames
provideMessageFrames(aA);
//OPEN PAGE OF RESULTS
if (aA.f + aA.ff > 0) {
resultsPage(aA);
}
}
function checkFramesFrames(myDocument,aA,placeToAddTo){
//function with all the specific detail, just to keep it separate
// it returns aA with new values after using it to count
//run check for each frame's document if there
// are any frames
//create object just to check length of the properties array
var jt_generic_obj = myDocument.createElement("var");
var jt_ie7 = false;
if (jt_generic_obj.attributes.length > 0) {
jt_ie7 = true;
}
var frametypes=new Array('frame','iframe');
for (var g=0;g<frametypes.length;g++) {
//for each tag
var myframes=myDocument.getElementsByTagName(frametypes[g]);
for (var h=0;h<myframes.length;h++) {
//for each frame
//count the frames
var t = myframes[h];
if (frametypes[g]=='frame') {
aA.f++;
}
if (frametypes[g]=='iframe') {
aA.ff++;
//outline frame & resize frame if needed
var toadd=0;
if (t.width<72) {
t.width=144;
toadd=1;
t.style.border='2px dotted red';
}
if (t.height<72) {
t.height=144;
toadd=1;
t.style.border='2px dotted red';
}
if (toadd===0) {
t.style.border='2px solid red';
}
aA.tiny=aA.tiny+toadd;
}
// each frame gets a ul for reporting
// attached to document at first, but
// cloned for whichever doc is it used in
var listAdd = document.createElement('ul');
listAdd.style.margin="0px 0px 0px 5px";
// create template li element that holds the error messages
var error = document.createElement('li');
error.style.color="red";
error.style.fontFamily="arial,sans-serif";
error.style.fontSize="12pt";
error.style.fontWeight="bold";
//error.style.backgroundColor="#f5deb3";
// create template li element that holds the regular messages
var info = document.createElement('li');
info.style.color="navy";
info.style.fontFamily="arial,sans-serif";
info.style.fontSize="12pt";
info.style.fontWeight="bold";
//info.style.backgroundColor="#f5deb3";
//get the frame info
//type of frame
var typeinfo = info.cloneNode(true);
listAdd.appendChild(typeinfo);
typeinfo.appendChild(document.createTextNode(frametypes[g]));
//title
if ((jt_ie7 && t.attributes.title.specified) || (!(jt_ie7) && t.hasAttribute('title'))) {
var titleinfo = info.cloneNode(true);
listAdd.appendChild(titleinfo);
titleinfo.appendChild(document.createTextNode('title="'+t.title+'"'));
} else {
var titleerror = error.cloneNode(true);
listAdd.appendChild(titleerror);
titleerror.appendChild(document.createTextNode("Error: no title attribute"));
if (frametypes[g]=='frame') {
aA.ef++;
}
if (frametypes[g]=='iframe') {
aA.eff++;
}
}
//name
if ((jt_ie7 && t.attributes.name.specified) || (!(jt_ie7) && t.hasAttribute('name'))) {
var nameinfo = info.cloneNode(true);
listAdd.appendChild(nameinfo);
nameinfo.appendChild(document.createTextNode('name="'+t.name+'"'));
} else {
var nameerror = info.cloneNode(true);
listAdd.appendChild(nameerror);
nameerror.appendChild(document.createTextNode("No name attribute"));
}
//src
if ((jt_ie7 && t.attributes.src.specified) || (!(jt_ie7) && t.hasAttribute('src'))) {
var srcinfo = info.cloneNode(true);
listAdd.appendChild(srcinfo);
srcinfo.appendChild(document.createTextNode('src="'));
var mySRClink = document.createElement('a');
mySRClink.setAttribute('href',t.src);
mySRClink.appendChild(document.createTextNode(t.src));
srcinfo.appendChild(mySRClink);
srcinfo.appendChild(document.createTextNode('"'));
mySRClink.style.color="navy";
} else {
var srcerror = info.cloneNode(true);
listAdd.appendChild(srcerror);
srcerror.appendChild(document.createTextNode("No src attribute"));
}
//prepare structure to add some info to each frame's document
try {
var insideDocument = t.contentWindow.document;
//remove anything added last time this favelet ran
//create object just to check length of the properties array
//need to check this for insideDocument specifically as it may
//have a different doctype from containing document
var jt_generic_obja = insideDocument.createElement("var");
var jt_ie7a = false;
if (jt_generic_obja.attributes.length > 0) {
jt_ie7a = true;
}
var myExpress1 = /fstAdded.*/;
var divLive=insideDocument.getElementsByTagName('div');
//static (divs won't change - don't use divLive while editing page)
var divs = [];
for (var i=0; i<divLive.length;i++) {
divs[i] = divLive[i];
}
for (var s=0;s<divs.length;s++) {
if (((jt_ie7a && divs[s].attributes && divs[s].attributes.id.specified) || (!(jt_ie7a) && divs[s].hasAttribute('id'))) && myExpress1.test(divs[s].getAttribute('id'))) {
divs[s].parentNode.removeChild(divs[s]);
}
}
//create div with special id so we can remove it later
var pageAdd = insideDocument.createElement('div');
pageAdd.id="fstAdded" + (aA.idi++);
pageAdd.style.backgroundColor="#FFFF00";
pageAdd.style.opacity=".8";
pageAdd.style.filter="alpha(opacity=85)";
pageAdd.style.position="absolute";
pageAdd.style.left="0px";
pageAdd.style.top="0px";
pageAdd.style.zIndex="50";
//pageAdd.style.border="2px solid navy";
pageAdd.style.padding="3px";
//add ul
var listAddinner = listAdd.cloneNode(true);
listAddinner.style.margin="0px 0px 0px 0px";
listAddinner.style.padding="0px 0px 0px 14px";
pageAdd.appendChild(listAddinner);
//s+=tag+'-'+(i+1)+'</li>\r';
//make the div the first thing in the inside doc
if (insideDocument.body.childNodes.length>0) {
insideDocument.body.insertBefore(pageAdd,insideDocument.body.childNodes[0]);
} else {
insideDocument.body.appendChild(pageAdd);
}
//recursion
var newPlace = listAdd.cloneNode(true);
checkFramesFrames(insideDocument,aA,newPlace);
} catch(e) {
var cant_reach = error.cloneNode(true);
listAdd.appendChild(cant_reach);
cant_reach.appendChild(document.createTextNode("This frame's document couldn't be written to or checked for additional frames."));
var newPlace = listAdd.cloneNode(true);
//errors are stored in aA too
aA.framemsg=aA.framemsg + '\n' + myframes[h].src + '\n\t' + e + '\n';
aA.fi=aA.fi + 1;
t.style.border='5px double red';
}
//SAVE INFO FOR RESULTS PAGE
newPlace.style.margin="10px 0px 0px 27px";
if (placeToAddTo.tagName == 'ul') {
var myLI = document.createElement('li');
placeToAddTo.appendChild(myLI);
myLI.appendChild(newPlace);
} else {
placeToAddTo.appendChild(newPlace);
}
}
}
return aA;
}
function resultsPage(aA) {
// Heading Above Lists
var myH = document.createElement("h1");
myH.appendChild(document.createTextNode('This page has '+aA.f+' frames and '+aA.ff+' iframes:'));
aA.infoTree.insertBefore(myH,aA.infoTree.childNodes[0]);
try {
var lw = window.open('','lw');
if (lw!==null) {
if (lw.opener === null) {
lw.opener = window;
}
// IE has no interface for DOM additions to pages
// that were created using DOM, but we still use
// DOM for most things and convert back to a string
// here using innerHTML
lw.document.open();
lw.document.write('<html><head><title>Report on Frame Accessibility</title></head><body>' + aA.infoTree.innerHTML + '</body></html>');
lw.document.close();
lw.focus();
} else {
alert('Popup windows for frame report blocked.');
}
} catch(err) {
alert('Window is not available: ' + '\nBe sure to close the frame report window each time it opens.');
return false;
}
}
function provideMessageFrames(aA) {
var x_pl='s';
var w_pl='s';
var y_pl='s';
if (aA.x==1){x_pl='';}
if (aA.w==1){w_pl='';}
if (aA.y==1){y_pl='';}
if ((aA.f+aA.ff)===0) {
var alertmessage = 'No frames or iframes';
} else {
var alertmessage = aA.ef + ' errors out of '+aA.f+' frames and '+aA.eff+' errors out of '+aA.ff+' iframes.\n\nCheck out list of frames that opens next.';
}
if(aA.tiny>0) {
alertmessage = alertmessage + '\n\n' + aA.tiny + ' tiny iframes resized (shown with a dotted border)';
}
var fi_pl='s';
if (aA.fi==1){fi_pl='';}
if (aA.fi>0) {
alertmessage=alertmessage + '\n\n' + aA.fi + ' frame'+fi_pl+' (shown with a double border) outside the domain could not be checked for additional frames: \n' + aA.framemsg;
}
alert(alertmessage);
}
startFrames();
//1-2-2011
// Completed first version of this as a stand alone favelet
//TO DO
// note when frames are hidden with display:none; etc - possible enhancement for all favelets