-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathandi.js
3587 lines (3244 loc) · 151 KB
/
andi.js
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//=============================================//
//ANDI: Accessible Name & Description Inspector//
//Created By Social Security Administration //
//=============================================//
var andiVersionNumber = "19.1.1";
//==============//
// ANDI CONFIG: //
//==============//
//URLs
var host_url = "https://www.ssa.gov/accessibility/andi/";
var help_url = host_url+"help/";
var icons_url = host_url+"icons/";
//Load andi.css file immediately to minimize page flash
var andiCss = document.createElement("link");
andiCss.href = host_url + "andi.css";
andiCss.type = "text/css";
andiCss.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(andiCss);
//Representation of Empty String that will appear on screen
AndiCheck.emptyString = "\"\"";
//This number is 2x breath interval of a screen reader (125 characters)
AndiCheck.characterLimiter = 250;
//Set the global animation speed
AndiSettings.andiAnimationSpeed = 50; //milliseconds
//The element highlights setting (true = on, false = off)
AndiSettings.elementHighlightsOn = true;
//Default Module
AndiModule.module = "f";
//===============//
// ANDI OBJECTS: //
//===============//
var andiResetter = new AndiResetter(); //Resets things ANDI changed
var andiSettings = new AndiSettings(); //Stores Settings
var andiBar = new AndiBar(); //Main Display
var andiHotkeyList = new AndiHotkeyList(); //Hotkey assignments/display panel
var andiCheck = new AndiCheck(); //Alert Testing
var andiAlerter = new AndiAlerter(); //Alert Throwing
var andiLaser = new AndiLaser(); //Laser Functionality
var andiFocuser = new AndiFocuser(); //Focusing Funtionality
var andiUtility = new AndiUtility(); //String Manipulation
var andiOverlay = new AndiOverlay(); //Used to create overlays
var testPageData; //Test Page Data Storage/Analysis, instantiated within module launch
var andiData; //Element Data Storage/Analysis, instatiated within module's analysis logic
var focusedElementAtLaunch; //Stores element which had focus at launch
var browserSupports = {
//Does the browser support SVG?
svg: typeof SVGRect !== "undefined"
};
//Define the overlay and find icons (not using background-image because of ie7 issues with sizing)
var overlayIcon = "<img src='"+icons_url+"overlay-off.png' class='ANDI508-overlayIcon' aria-label='overLay' />";
var findIcon = "<img src='"+icons_url+"find-off.png' class='ANDI508-findIcon' aria-label='find' />";
var listIcon = "<img src='"+icons_url+"list-off.png' class='ANDI508-listIcon' alt='' />";
//==================//
// ANDI INITIALIZE: //
//==================//
//This main function is called when jQuery is ready.
function launchAndi(){(window.andi508 = function(){
//Ensure that $ is mapped to jQuery
window.jQuery = window.$ = jQuery;
//Frames handling
if(document.getElementsByTagName("frameset")[0]){
if(confirm("ANDI has detected frames:\nPress OK to stay on the page.\nPress Cancel to test an individual frame.") !== true){
var framesSelectionLinks = "<head><title>ANDI Frame Selection</title></head><body id='ANDI508-frameSelectionUI'><h1 style='font:bold 20pt Verdana'>ANDI</h1>"+
"<p style='font:12pt Verdana'>This page, '"+document.title+"', uses frames. Each frame must be tested individually. <br />Select a frame from the list below, then launch ANDI.</p>"+
"<h2 style='font:bold 13pt Verdana'>Frames:</h2><ol>";
var title, titleDisplay;
$("frame").each(function(){
//Build Title Display
title = $(this).attr("title");
titleDisplay = " ";
if(!title)
titleDisplay += "<span style='color:red; font-family:verdana'>Alert: <img style='width:18px' src='"+icons_url+"danger.png' alt='danger: ' /> No title attribute on this <frame>.";
else
titleDisplay += '<span style=\"font-family:verdana\">title=\"'+ title + '\"';
titleDisplay += "</span>";
framesSelectionLinks += "<li><a href='"+$(this).attr("src")+"' style='font-family:monospace'>"+$(this).attr("src")+"</a>"+titleDisplay+"</li>";
});
framesSelectionLinks += "</ol><button style='font:10pt Verdana;' onclick='window.history.back()'>Go Back</button></body>";
document.write(framesSelectionLinks);
}
else{
//Reload the test page so that the ANDI files that were added are removed.
location.reload();
}
return; //Stops ANDI
}
else{
//iFrames handling
var iFrames = $("iframe[src]").filter(":visible");
if($(iFrames).length > 0){
//Frames or iFrames Detected: Present the Show Frame Selection Interface
if(confirm("ANDI has detected iframes:\nPress OK to test the main page.\nPress Cancel to test an individual iframe.") !== true){
var iframesSelectionLinks = "<head><title>ANDI Iframe Selection</title></head><body id='ANDI508-frameSelectionUI'><h1 style='font:bold 20pt Verdana'>ANDI</h1>"+
"<p style='font:12pt Verdana'>This page, '"+document.title+"', contains iframes. Each iframe must be tested individually. <br />Select an iframe from the list below, then launch ANDI.</p>"+
"<h2 style='font:bold 13pt Verdana'>Iframes:</h2><ol>";
$(iFrames).each(function(){
//Build Title Display
if($(this).attr("src") !== "")
iframesSelectionLinks += "<li><a href='"+$(this).attr("src")+"' style='font-family:monospace'>"+$(this).attr("src")+"</a></li>";
});
iframesSelectionLinks += "</ol><button style='font:10pt Verdana;' onclick='window.history.back()'>Go Back</button></body>";
document.write(iframesSelectionLinks);
return;
}
}
}
//Prevent running ANDI on the frame selection UI
if(document.getElementById("ANDI508-frameSelectionUI")){
//ANDI was launched while the frame selection UI was open.
alert("Select a frame, then launch ANDI.");
return;
}
//Get ANDI ready to launch the first module
andiReady();
//Store element that had focus at launch
focusedElementAtLaunch = $(":focus");
//Default Module Launch
AndiModule.launchModule(AndiModule.module);
//Load previously saved settings.
andiSettings.loadANDIsettings();
//Push down test page so ANDI display can be fixed at top of screen.
andiResetter.resizeHeightsOnWindowResize();
})();}
//==============//
// ANDI MODULE: //
//==============//
//This class defines an Andi Module.
//Should be instantiated in the module's js file.
//All ANDI modules (besides the default) should have a *andi.css file which will be loaded when the module is launched.
function AndiModule(moduleVersionNumber, moduleLetter){
//Display the module letter in the logo when the module is instantiated
var moduleName = $("#ANDI508-module-name");
$(moduleName).attr("data-ANDI508-module-version",moduleLetter+"ANDI: "+moduleVersionNumber);
if(moduleLetter == "f"){
$(moduleName).html(" "); //do not display default module letter
document.getElementById("ANDI508-toolName-link").setAttribute("aria-label", "andi "+andiVersionNumber); //using setAttribute because jquery .attr("aria-label") is not recognized by ie7
}
else{
$(moduleName).html(moduleLetter);
document.getElementById("ANDI508-toolName-link").setAttribute("aria-label", moduleLetter+"andi "+moduleVersionNumber); //using setAttribute because jquery .attr("aria-label") is not recognized by ie7
$("head").append("<link id='andiModuleCss' href='"+host_url+moduleLetter+"andi.css' type='text/css' rel='stylesheet' />");
}
//Module Selection Menu Operation
$("#ANDI508-moduleMenu")
.on("mouseover",AndiModule.showMenu)
.on("mouseleave",AndiModule.hideMenu);
$("#ANDI508-moduleMenu button")
.on("focusout",AndiModule.hideMenu)
.on("focus",AndiModule.showMenu)
.on("keydown",function(event){
var keyCode = event.keyCode || event.which;
switch(keyCode){
case 40: //down
$(this).nextAll().filter(":visible").first().focus();
break;
case 38: //up
$(this).prevAll().filter(":visible").first().focus();
break;
}
});
//The module should implement these priveleged methods
this.analyze = undefined;
this.results = undefined;
this.inspect = undefined;
//Previous Element Button - modules may overwrite this
//Instantiating a module will reset any overrides
$("#ANDI508-button-prevElement").off("click").click(function(){
var index = parseInt($("#ANDI508-testPage .ANDI508-element-active").attr("data-ANDI508-index"));
if(isNaN(index)) //no active element yet
andiFocuser.focusByIndex(1); //first element
else if(index == 1)
andiFocuser.focusByIndex(testPageData.andiElementIndex); //loop back to last
else{
//Find the previous element with data-ANDI508-index
//This will skip over elements that may have been removed from the DOM
for(var x=index; x>0; x--){
if($("#ANDI508-testPage [data-ANDI508-index='"+(x - 1)+"']").length){
andiFocuser.focusByIndex(x - 1);
break;
}
}
}
});
//Next Element Button - modules may overwrite this
//Instantiating a module will reset any overrides
$("#ANDI508-button-nextElement").off("click").click(function(){
var index = parseInt($("#ANDI508-testPage .ANDI508-element-active").attr("data-ANDI508-index"));
if(index == testPageData.andiElementIndex || isNaN(index))
andiFocuser.focusByIndex(1); //loop back to first
else{
//Find the next element with data-ANDI508-index
//This will skip over elements that may have been removed from the DOM
for(var x=index; x<testPageData.andiElementIndex; x++){
if($("#ANDI508-testPage [data-ANDI508-index='"+(x + 1)+"']").length){
andiFocuser.focusByIndex(x + 1);
break;
}
}
}
});
}
//The module should implement these public methods
AndiModule.prototype.andiElementHoverability = undefined;
AndiModule.prototype.andiElementFocusability = undefined;
//This defines the core output logic for ANDI
AndiModule.outputLogic = function(elementData){
var usingTitleAsNamer = false;
var usingSummaryAsNamer = false;
//groupingText
if(andiBar.output.groupingText(elementData));
//legend
if(!elementData.ignoreLegend && andiBar.output.legend(elementData));
//Accessible Name
//aria-labelledby
if(andiBar.output.ariaLabelledby(elementData));
//aria-label
else if(andiBar.output.ariaLabel(elementData));
//HTML Namers
//label
else if(!elementData.ignoreLabel && andiBar.output.label(elementData));
//alt
else if(!elementData.ignoreAlt && andiBar.output.alt(elementData));
//figcaption
else if(!elementData.ignoreFigcaption && andiBar.output.figcaption(elementData));
//caption
else if(!elementData.ignoreCaption && andiBar.output.caption(elementData));
//value
else if(andiBar.output.value(elementData));
//summary
else if(andiBar.output.summary(elementData)) usingSummaryAsNamer=true;
//innerText/child
else if(andiBar.output.innerText(elementData));
//title
else if(andiBar.output.title(elementData)) usingTitleAsNamer=true;
//Accessible Description
//aria-describedby
if(andiBar.output.ariaDescribedby(elementData));
//HTML Describers
//summary
else if(!usingSummaryAsNamer && andiBar.output.summary(elementData));
//title
else if(!usingTitleAsNamer && andiBar.output.title(elementData));
//Add-On Properties
if(andiBar.output.addOnProperties(elementData));
};
//The modules will keep track of the pressed action buttons using this variable.
//When the module is refreshed, the buttons remain pressed.
//If a different module is selected, the buttons will be unpressed.
AndiModule.activeActionButtons = {};
//The functions show/hide the module selection menu
AndiModule.showMenu = function(){
$("#ANDI508-moduleMenu").addClass("ANDI508-moduleMenu-expanded");
};
AndiModule.hideMenu = function(){
//setTimeout and :focus check are needed to fix a timing issue in firefox and chrome
setTimeout(function(){
if(!$(":focus").hasClass("ANDI508-moduleMenu-option"))
$("#ANDI508-moduleMenu").removeClass("ANDI508-moduleMenu-expanded");
}, 5);
};
//This function will launch a module.
//Parameters:
// module: the letter of the module
AndiModule.launchModule = function(module){
//Remove previously selected modules
$("#ANDI508-moduleMenu button")
.attr("tabindex","-1")
.removeClass("ANDI508-moduleMenu-selected ANDI508-moduleMenu-unavailable")
.removeAttr("aria-selected")
.find("img").first().remove();
//Select this module
$("#ANDI508-moduleMenu-button-"+module)
.addClass("ANDI508-moduleMenu-selected")
.attr("tabindex","0")
.attr("aria-selected","true")
.append("<img src='"+icons_url+"dropdown.png' role='presentation' />");
andiBar.showModuleLoading();
setTimeout(function(){//Slight delay so that the ANDI bar appears earlier
$("#ANDI508-testPage").addClass(module+"ANDI508-testPage");
//if current module is not this module
if(AndiModule.module != module){
AndiModule.module = module; //Set current module to launched module
AndiModule.activeActionButtons = {}; //Reset action buttons
}
testPageData = new TestPageData(); //get fresh test page data
//Global Checks
andiCheck.isThereExactlyOnePageTitle();
andiCheck.areThereMoreExclusiveChildrenThanParents();
//Load the module's script
var script = document.createElement("script");
var done = false;
script.src = host_url + module + "andi.js";
script.type="text/javascript";
script.id="andiModuleScript";
script.onload = script.onreadystatechange = function(){if(!done && (!this.readyState || this.readyState=="loaded" || this.readyState=="complete")){done=true; init_module();}};
$("#andiModuleScript").remove(); //Remove previously added module script
$("#andiModuleCss").remove();//remove previously added module css
//Execute the module's script
document.getElementsByTagName("head")[0].appendChild(script);
$("#ANDI508").removeClass().addClass("ANDI508-module-"+module).show();
andiBar.hideModuleLoading();
andiResetter.resizeHeights();
},1);//end setTimeout
};
//This function will hide the module corresponding to the letter passed in
//unless the active module is the letter passed in
AndiModule.disableModuleButton = function(letter){
if(AndiModule.module != letter) //This prevents disabling the module that is currently selected when no corresponding
$("#ANDI508-moduleMenu-button-"+letter).addClass("ANDI508-moduleMenu-unavailable");
};
//================//
// ALERT MESSAGES //
//================//
//This defines the class Alert
function Alert(level, group, message, info, alertButton){
this.level = level; //danger, warning, or caution
this.group = group; //belongs to this alert group id
this.message = message; //message text
this.info = info; //the id corresponding to the help page documentation
this.alertButton = alertButton; //(optional) an alert button object
this.list = ""; //variable for holding a list
}
//Define Alerts used by all modules
var alert_0001 = new Alert("danger","0"," has no accessible name, associated <label>, or [title].","#no_name");
var alert_0002 = new Alert("danger","0"," has no accessible name, innerText, or [title].","#no_name");
var alert_0003 = new Alert("danger","0"," has no accessible name, [alt], or [title].","#no_name");
var alert_0004 = new Alert("danger","0","Table has no accessible name, <caption>, or [title].","#no_name");
var alert_0005 = new Alert("danger","0","Figure has no accessible name, <figcaption>, or [title].","#no_name");
var alert_0006 = new Alert("warning","0","[placeholder] provided, but element has no accessible name.","#placeholder_no_name");
var alert_0007 = new Alert("warning","0","Iframe is in the keyboard tab order and has no accessible name or [title].","#iframe_tab_order");
var alert_0011 = new Alert("danger","1","Duplicate id found [id=%%%]; Element ids should be unique.","#dup_id",
new AlertButton("show ids", "ANDI508-alertButton-duplicateIdOverlay", function(){andiOverlay.overlay_duplicateIds();}, overlayIcon));
var alert_0012 = new Alert("danger","1","More than one <label[for=%%%]> associates with this element [id=%%%].","#dup_for");
var alert_0021 = new Alert("danger","2","Using [aria-describedby] alone on this element causes screen reader inconsistencies.","#dby_alone");
var alert_0022 = new Alert("danger","2","Using <legend> alone on this element causes screen reader inconsistencies.","#legend_alone");
var alert_0031 = new Alert("danger","3","[aria-labeledby] is mispelled, use [aria-labelledby].","#misspell");
var alert_0032 = new Alert("danger","3","[aria-role] not a valid attribute, use [role] instead.","#aria_role");
var alert_0041 = new Alert("warning","4","Presentation tables should not use data table markup: %%%.","#pres_table_not_have");
var alert_0043 = new Alert("caution","4","Table has more than %%% levels of [scope=%%%].","#too_many_scope_levels");
var alert_0044 = new Alert("danger","4","Scope attribute value [scope=%%%] is invalid.","#scope_invalid");
var alert_0045 = new Alert("danger","4","[headers] attribute only valid on <th> or <td>.","#headers_only_for_th_td");
var alert_0046 = new Alert("danger","4","Table has no <th> cells.","#table_has_no_th");
var alert_0047 = new Alert("warning","4","Scope association needed at intersection of <th>.","#no_scope_at_intersection");
var alert_0048 = new Alert("caution","4","Table has no [scope] associations.","#table_has_no_scope");
var alert_0049 = new Alert("danger","4","Table using both [scope] and [headers], may cause screen reader issues.","#table_mixing_scope_and_headers");
var alert_004A = new Alert("danger","4","Table has no [headers/id] associations.","#table_has_no_headers");
var alert_004B = new Alert("danger","4","Table has no [scope] but does have [headers], switch to 'headers/id mode'.","#switch_table_analysis_mode");
var alert_004C = new Alert("danger","4","Table has no [headers/id] but does have [scope], switch to 'scope mode'.","#switch_table_analysis_mode");
var alert_004E = new Alert("danger","4","Table has no <th> or <td> cells.","#table_has_no_th_or_td");
var alert_0052 = new Alert("danger","5","[accessKey] value \"%%%\" has more than one character.","#accesskey_more_one");
var alert_0054 = new Alert("danger","5","Duplicate [accessKey=%%%] found on button.","#accesskey_duplicate");
var alert_0055 = new Alert("caution","5","Duplicate [accessKey=%%%] found.","#accesskey_duplicate");
var alert_0056 = new Alert("danger","5","Duplicate [accessKey=%%%] found on link.","#accesskey_duplicate");
var alert_0061 = new Alert("danger","6","Element\'s [aria-labelledby] references provide no name text.","#lby_refs_no_text");
var alert_0062 = new Alert("warning","6","Element\'s [aria-describedby] references provide no description text.","#dby_refs_no_text");
var alert_0063 = new Alert("warning","6","Element referenced by [%%%] with [id=%%%] not found.","#ref_id_not_found");
var alert_0064 = new Alert("caution","6","[%%%] reference contains [aria-label].","#ref_has_aria_label");
var alert_0065 = new Alert("danger","6","Improper use of [%%%] possible: Referenced ids \"%%%\" not found.","#improper_ref_id_usage");
var alert_0066 = new Alert("danger","6","Element referenced by [headers] attribute with [id=%%%] is not a <th>.","#headers_ref_not_th");
var alert_0067 = new Alert("warning","6","[headers] attribute with [id=%%%] is referencing a <td>.","#headers_ref_is_td");
var alert_0068 = new Alert("warning","6","Element\'s [headers] references provide no association text.","#headers_refs_no_text");
var alert_0069 = new Alert("warning","6","In-page anchor target with [id=%%%] not found.","#anchor_target_not_found");
var alert_006A = new Alert("danger","6","<img> referenced by image map %%% not found.","#image_map_ref_not_found");
var alert_0071 = new Alert("danger","7","Page <title> cannot be empty.","#page_title_empty");
var alert_0072 = new Alert("danger","7","Page has no <title>.","#page_title_none");
var alert_0073 = new Alert("danger","7","Page has more than one <title> tag.","#page_title_multiple");
var alert_0074 = new Alert("danger","7","There are more legends (%%%) than fieldsets (%%%).","#too_many_legends");
var alert_0075 = new Alert("danger","7","There are more figcaptions (%%%) than figures (%%%).","#too_many_figcaptions");
var alert_0076 = new Alert("danger","7","There are more captions (%%%) than tables (%%%).","#too_many_captions");
var alert_0077 = new Alert("danger","7","Tabindex value \"%%%\" is not a number.","#tabindex_not_number");
var alert_0078 = new Alert("warning","7","Using HTML5, found deprecated %%%.","#deprecated_html");
var alert_0079 = new Alert("danger","7","List item <li> is not contained by a list container <ol> or <ul>.","#li_no_container");
var alert_007A = new Alert("danger","7","Description list item is not contained by a description list container <dl>.","#dd_dt_no_container");
var alert_0081 = new Alert("warning","8","[alt] attribute is meant for <img>, use [aria-label] on this element.","#alt_only_for_images");
var alert_0091 = new Alert("warning","9","Explicit <label[for]> only works with form elements.","#explicit_label_for_forms");
var alert_0092 = new Alert("warning","9","Explicit <label[for]> shouldn't be used with buttons.","#explicit_label_not_for_buttons");
var alert_0101 = new Alert("warning","10","Combining %%% produces inconsistent screen reader results.","#unreliable_component_combine");
var alert_0112 = new Alert("caution","11","JavaScript event %%% may cause keyboard accessibility issues; investigate.","#javascript_event_caution");
var alert_0121 = new Alert("caution","12","Focusable element not in keyboard tab order.","#not_in_tab_order");
var alert_0122 = new Alert("caution","12","Focusable element not in keyboard tab order and has no accessible name.","#not_in_tab_order_no_name");
var alert_0124 = new Alert("caution","12","Iframe is in the keyboard tab order.","#iframe_tab_order");
var alert_0125 = new Alert("warning","16","Element with [role=%%%] not in the keyboard tab order.","#role_tab_order");
var alert_0126 = new Alert("danger","17","Image defined as decorative is in the keyboard tab order.","#decorative_image_tab_order");
var alert_0131 = new Alert("caution","13","Empty component:%%%.","#empty_component");
var alert_0132 = new Alert("caution","13","Empty <th> cell.","#empty_header_cell");
var alert_0141 = new Alert("caution","14","Child element component%%%has unused text.","#child_unused_text");
var alert_0151 = new Alert("warning","15","[title] attribute length exceeds "+AndiCheck.characterLimiter+" characters.","#character_length");
var alert_0152 = new Alert("warning","15","[alt] attribute length exceeds "+AndiCheck.characterLimiter+" characters.","#character_length");
var alert_0153 = new Alert("warning","15","[aria-label] length exceeds "+AndiCheck.characterLimiter+" characters.","#character_length");
var alert_0161 = new Alert("warning","16","Ambiguous Link: same name/description as another link but different href.","#ambiguous_link");
var alert_0162 = new Alert("caution","16","Ambiguous Link: same name/description as another link but different href.","#ambiguous_link");//caution level thrown for internal links
var alert_0163 = new Alert("caution","16","Link text is vague and does not identify its purpose.","#vague_link");
var alert_0164 = new Alert("warning","16","Link has click event but is not keyboard accessible.","#link_click_no_keyboard_access");
var alert_0165 = new Alert("caution","16","<a> tag has no [href], [id], or [tabindex].","#anchor_no_href_id_tabindex");
var alert_0171 = new Alert("danger","17","<marquee> element found, do not use.","#marquee_found");
var alert_0172 = new Alert("danger","17","<blink> element found, do not use.","#blink_found");
var alert_0173 = new Alert("danger","17","Server side image map found, do not use.","#server_side_image_map");
var alert_0174 = new Alert("caution","17","Redundant phrase in image [alt] text.","#image_alt_redundant_phrase");
var alert_0175 = new Alert("warning","17","Image [alt] text contains file name.","#image_alt_contains_file_name");
var alert_0176 = new Alert("danger","17","Image [alt] text is not descriptive.","#image_alt_not_descriptive");
var alert_0177 = new Alert("caution","17","Ensure that background images are decorative.","#ensure_bg_images_decorative");
var alert_0178 = new Alert("danger","17","<area> not contained in <map>.","#area_not_in_map");
var alert_0180 = new Alert("danger","18","[role=heading] used without [aria-level].","#role_heading_no_arialevel");
var alert_0181 = new Alert("danger","18","Tabbable element is hidden from screen reader using [aria-hidden=true].","#tabbable_ariahidden");
var alert_0190 = new Alert("warning","19","Element visually conveys heading meaning but not using semantic heading markup.","#not_semantic_heading");
var alert_0200 = new Alert("warning","20","Non-unique button: same name/description as another button.","#non_unique_button");
var alert_0210 = new Alert("caution","21","An associated <label> would increase the clickable area of this %%%.","#label_clickable_area");
var alert_0220 = new Alert("danger","22","Text content has been injected using CSS pseudo-elements ::before or ::after.","#pseudo_before_after");
var alert_0230 = new Alert("warning","23","Element has background-image; Perform manual contrast test.","#manual_contrast_test_bgimage");
var alert_0231 = new Alert("caution","23","Page has images; If images contain meaningful text, perform manual contrast test.","#manual_contrast_test_img");
var alert_0232 = new Alert("warning","23","Opacity less than 100%; Perform manual contrast test.","#manual_contrast_test_opacity");
var alert_0240 = new Alert("danger","24","Text does not meet %%%minimum %%% contrast ratio (%%%:1).","#min_contrast");
var alert_0250 = new Alert("warning","25","Page has %%% disabled %%%; Disabled elements are invisible to a screen reader.","#disabled_elements",
new AlertButton("show disabled", "ANDI508-alertButton-disabledElementsOverlay", function(){andiOverlay.overlay_disabledElements();}, overlayIcon));
var alert_0251 = new Alert("caution","25","Page has %%% disabled elements; Disabled elements do not require sufficient contrast.","#disabled_contrast",
new AlertButton("show disabled", "ANDI508-alertButton-disabledElementsOverlay", function(){andiOverlay.overlay_disabledElements(true);}, overlayIcon));
//==================//
// DISPLAY HANDLING //
//==================//
//This private function will get ANDI ready
//Will add dependencies, insert the ANDI bar, add legacy css, define the controls
function andiReady(){
andiResetter.hardReset();
dependencies();
appendLegacyCss();
insertAndiBarHtml();
defineControls();
//This function creates main html structure of the ANDI Bar.
function insertAndiBarHtml(){
var menuButtons =
"<button id='ANDI508-button-relaunch' aria-label='Relaunch ANDI' title='Press To Relaunch ANDI' accesskey='"+andiHotkeyList.key_relaunch.key+"'><img src='"+icons_url+"reload.png' alt='' /></button>"+ //refresh
"<button id='ANDI508-button-highlights' aria-label='Element Highlights' title='Press to Hide Element Highlights' aria-pressed='true'><img src='"+icons_url+"highlights-on.png' alt='' /></button>"+ //lightbulb
"<button id='ANDI508-button-minimode' aria-label='Mini Mode' title='Press to Engage Mini Mode'><img src='"+icons_url+"more.png' alt='' /></button>"+
"<button id='ANDI508-button-keys' aria-label='ANDI Hotkeys List' title='Press to Show ANDI Hotkeys List'><img src='"+icons_url+"keys-off.png' alt='' /></button>"+
andiHotkeyList.buildHotkeyList()+
"<button id='ANDI508-button-help' aria-label='ANDI Help' title='Press to Open ANDI Help Page in New Window'><img src='"+icons_url+"help.png' alt='' /></button>"+
"<button id='ANDI508-button-close' aria-label='Remove ANDI' title='Press to Remove ANDI'><img src='"+icons_url+"close.png' alt='' /></button>";
var moduleButtons = "<div id='ANDI508-moduleMenu' role='menu'><div id='ANDI508-moduleMenu-prompt'>Select Module:</div>"+
//Default
"<button role='menuitem' class='ANDI508-moduleMenu-option' id='ANDI508-moduleMenu-button-f'>focusable elements</button>"+
//gANDI
"<button role='menuitem' class='ANDI508-moduleMenu-option' id='ANDI508-moduleMenu-button-g'>graphics/images</button>"+
//lANDI
"<button role='menuitem' class='ANDI508-moduleMenu-option' id='ANDI508-moduleMenu-button-l'>links/buttons</button>"+
//tANDI
"<button role='menuitem' class='ANDI508-moduleMenu-option' id='ANDI508-moduleMenu-button-t'>tables</button>"+
//sANDI
"<button role='menuitem' class='ANDI508-moduleMenu-option' id='ANDI508-moduleMenu-button-s'>structures</button>";
if(!oldIE){
//cANDI
moduleButtons +="<button role='menuitem' class='ANDI508-moduleMenu-option' id='ANDI508-moduleMenu-button-c'>color contrast</button>";
}
//hANDI
moduleButtons +="<button role='menuitem' class='ANDI508-moduleMenu-option' id='ANDI508-moduleMenu-button-h'>hidden content</button>";
moduleButtons +="</div>";
var andiBar = "\
<section id='ANDI508' tabindex='0' aria-label='ANDI Accessibility Test Tool' style='display:none'>\
<div id='ANDI508-header'>\
<h1 id='ANDI508-toolName-heading' tabindex='-1' accesskey='"+andiHotkeyList.key_jump.key+"'><a id='ANDI508-toolName-link' href='#' aria-haspopup='true' aria-label='ANDI "+andiVersionNumber+"'><span id='ANDI508-module-name' data-ANDI508-module-version=''> </span>ANDI</a></h1>\
<div id='ANDI508-moduleMenu-container'>\
"+moduleButtons+"\
</div>\
<div id='ANDI508-module-actions'></div>\
<div id='ANDI508-loading'>Loading <div id='ANDI508-loading-animation' /></div>\
<div id='ANDI508-barControls' tabindex='-1' accesskey='"+andiHotkeyList.key_jump.key+"'><h2 class='ANDI508-screenReaderOnly'>ANDI Controls</h2>\
"+menuButtons+"\
</div>\
</div>\
<div id='ANDI508-body' style='display:none'>\
<div id='ANDI508-activeElementInspection' tabindex='-1' accesskey='"+andiHotkeyList.key_jump.key+"'><h2 class='ANDI508-screenReaderOnly'>ANDI Active Element Inspection</h2>\
<div id='ANDI508-activeElementResults'>\
<div id='ANDI508-elementControls'>\
<button aria-label='Previous Element' title='Focus on Previous Element' accesskey='"+andiHotkeyList.key_prev.key+"' id='ANDI508-button-prevElement'><img src='"+icons_url+"prev.png' alt='' /></button>\
<button aria-label='Next Element' title='Focus on Next Element' accesskey='"+andiHotkeyList.key_next.key+"' id='ANDI508-button-nextElement'><img src='"+icons_url+"next.png' alt='' /></button>\
<br />\
</div>\
<div id='ANDI508-startUpSummary' tabindex='0' />\
<div id='ANDI508-elementDetails'>\
<div id='ANDI508-elementNameContainer'><h3 class='ANDI508-heading'>Element:</h3>\
<a href='#' id='ANDI508-elementNameLink' aria-labelledby='ANDI508-elementNameContainer'><<span id='ANDI508-elementNameDisplay' />></a>\
</div>\
<div id='ANDI508-additionalElementDetails'></div>\
<div id='ANDI508-accessibleComponentsTableContainer'>\
<h3 id='ANDI508-accessibleComponentsTable-heading' class='ANDI508-heading' tabindex='0'>Accessibility Components: <span id='ANDI508-accessibleComponentsTotal'></span></h3>\
<table id='ANDI508-accessibleComponentsTable' aria-labelledby='ANDI508-accessibleComponentsTable-heading'><tbody tabindex='0' /></table>\
</div>\
<div id='ANDI508-outputContainer'>\
<h3 class='ANDI508-heading' id='ANDI508-output-heading'>ANDI Output:</h3>\
<div id='ANDI508-outputText' tabindex='0' accesskey='"+andiHotkeyList.key_output.key+"' aria-labelledby='ANDI508-output-heading ANDI508-outputText' />\
</div>\
</div>\
</div>\
</div>\
<div id='ANDI508-pageAnalysis' tabindex='-1' accesskey='"+andiHotkeyList.key_jump.key+"'><h2 class='ANDI508-screenReaderOnly'>ANDI Page Analysis</h2>\
<div id='ANDI508-resultsSummary'>\
<h3 class='ANDI508-heading' tabindex='0' id='ANDI508-resultsSummary-heading'></h3>\
</div>\
<div id='ANDI508-additionalPageResults' />\
<div id='ANDI508-alerts-list' />\
</div>\
</div>\
</section>\
";
if(browserSupports.svg)
andiBar += "<svg id='ANDI508-laser-container'><title>ANDI Laser</title><line id='ANDI508-laser' /></svg>";
var body = $("body");
//Preserve original body padding and margin
var body_padding = "padding:"+$(body).css("padding-top")+" "+$(body).css("padding-right")+" "+$(body).css("padding-bottom")+" "+$(body).css("padding-left")+"; ";
var body_margin = "margin:"+$(body).css("margin-top")+" 0px "+$(body).css("margin-bottom")+" 0px; ";
$("html").addClass("ANDI508-testPage");
$(body)
.addClass("ANDI508-testPage")
.wrapInner("<div id='ANDI508-testPage' style='"+body_padding+body_margin+"' />") //Add an outer container to the test page
.prepend(andiBar); //insert ANDI display into body
}
//This function appends css shims to the head of the page which are needed for old IE versions
function appendLegacyCss(){
if(oldIE){
$("head").append("<!--[if lte IE 7]><link href='"+host_url+"ie7.css' rel='stylesheet' /><![endif]-->"+
"<!--[if lt IE 9]><link href='"+host_url+"ie8.css' rel='stylesheet' /><![endif]-->");
}
}
//This function defines what the ANDI controls/settings do.
//Controls are: Relaunch, Highlights, Mini Mode, Hotkey List, Help, Close, TagName link,
// prev/next button, module laucnhers, active element jump hotkey, version popup
function defineControls(){
//ANDI Relaunch Button
$("#ANDI508-button-relaunch").click(function(){
$("#ANDI508-moduleMenu-button-"+AndiModule.module).click();
return false;
});
//Highlights Button
$("#ANDI508-button-highlights").click(function(){
if (!AndiSettings.elementHighlightsOn){
//Show Highlights
$("#ANDI508-testPage .ANDI508-element").addClass("ANDI508-highlight");
$(this)
.attr("title","Press to Hide Element Highlights")
.attr("aria-pressed","true")
.children("img").first().attr("src",icons_url+"highlights-on.png");
AndiSettings.elementHighlightsOn = true;
}else{
//Hide Highlights
$("#ANDI508-testPage .ANDI508-highlight").removeClass("ANDI508-highlight");
$(this)
.attr("title","Press to Show Element Highlights")
.attr("aria-pressed","false")
.children("img").first().attr("src",icons_url+"highlights-off.png");
AndiSettings.elementHighlightsOn = false;
}
andiResetter.resizeHeights();
});
//Mini Mode Button
$("#ANDI508-button-minimode").click(function(){
if($("#ANDI508-body").hasClass("ANDI508-minimode"))
andiSettings.minimode(false);
else
andiSettings.minimode(true);
andiSettings.saveANDIsettings();
});
//Hotkeys List Button
$("#ANDI508-button-keys")
.click(function(){
if($("#ANDI508-hotkeyList").css("display")=="none")
andiHotkeyList.showHotkeysList();
else
andiHotkeyList.hideHotkeysList();
})
.focus(andiHotkeyList.hideHotkeysList);
andiHotkeyList.addArrowNavigation();
//ANDI Help Button
$("#ANDI508-button-help")
.click(function(){
var helpLocation = "howtouse.html";
if(AndiModule.module != "f") //jump directly to the module on the help page
helpLocation = "modules.html#" + AndiModule.module + "ANDI";
window.open(help_url+helpLocation, "_ANDIhelp",'width=1010,height=768,scrollbars=yes,resizable=yes').focus();
})
.focus(andiHotkeyList.hideHotkeysList);
//ANDI Remove/Close Button
$("#ANDI508-button-close").click(function(){
$("#ANDI508-testPage .ANDI508-element-active").first().removeClass("ANDI508-element-active");
andiResetter.hardReset();
});
//Tag name link
$("#ANDI508-elementNameLink")
.click(function(){ //Place focus on active element when click tagname
andiFocuser.focusByIndex($("#ANDI508-testPage .ANDI508-element-active").attr("data-ANDI508-index"));
andiLaser.eraseLaser();
return false;
})
.hover(function(){ //Draw line to active element
andiLaser.drawLaser($(this).offset(),$("#ANDI508-testPage .ANDI508-element-active").offset(),$("#ANDI508-testPage .ANDI508-element-active"));
})
.on("mouseleave", andiLaser.eraseLaser);
//Active Element Jump Hotkey
$(document).keydown(function(e){
if(e.which === andiHotkeyList.key_active.code && e.altKey )
$("#ANDI508-testPage .ANDI508-element-active").focus();
});
//Module Launchers
$("#ANDI508-moduleMenu").children("button").each(function(){
$(this).click(function(){
andiResetter.softReset($("#ANDI508-testPage"));
AndiModule.launchModule(this.id.slice(-1)); //pass the letter of the module (last character of id)
});
});
//ANDI Version Popup
$("#ANDI508-toolName-link").click(function(){
alert("ANDI "+andiVersionNumber+"\n"+$("#ANDI508-module-name").attr("data-ANDI508-module-version"));
return false;
});
}
//This function sets up several dependencies for running ANDI on the test page.
function dependencies(){
//Define :focusable and :tabbable pseudo classes. Code from jQuery UI
$.extend($.expr[ ':' ], {data: $.expr.createPseudo ? $.expr.createPseudo(function(dataName){return function(elem){return !!$.data(elem, dataName);};}) : function(elem, i, match){return !!$.data(elem, match[ 3 ]);},
focusable: function(element){return focusable(element, !isNaN($.attr(element, 'tabindex')));},
tabbable: function(element){var tabIndex = $.attr(element, 'tabindex'),isTabIndexNaN = isNaN(tabIndex); return (isTabIndexNaN || tabIndex >= 0) && focusable(element, !isTabIndexNaN);
}});
//Define :shown
//Similar to :visible but doesn't include elements with visibility:hidden,
$.extend(jQuery.expr[':'], {
shown: function (elem, index, selector){return $(elem).css("visibility") !== "hidden" && !$(elem).is(":hidden");}
});
//Define focusable function: Determines if something is focusable and its ancestors are visible.
//Code based on jQuery UI, modifications: disabled links, svg[focusable=true], tabindex=""
function focusable(element){
var nodeName = element.nodeName.toLowerCase();
var tabindex = $.attr(element, "tabindex"); //intentionally using jquery
var isTabIndexNotNaN = !isNaN(tabindex) && tabindex !== "";
if(nodeName === "area"){
var map = element.parentNode; var mapName = map.name;
if(!element.href || !mapName || map.nodeName.toLowerCase() !== "map") return false;
var img = $("img[usemap=\\#" + mapName + "]")[0]; return !!img && visibleParents(img);
}
return ( /^(input|select|textarea|button|object|iframe)$/.test(nodeName) ?
!element.disabled
: nodeName === "a" ?
(element.href && !element.disabled) || isTabIndexNotNaN
: isTabIndexNotNaN || (nodeName === "svg" && $.attr(element, "focusable") === "true")) && visibleParents(element);
function visibleParents(element){
return !$(element).parents().addBack().filter(function(){
return $.css(this, "visibility") === "hidden";
}).length;
}
}
//Define .includes() to make indexOf more readable.
if (!String.prototype.includes){
String.prototype.includes = function(search, start){
'use strict';
if(typeof start !== "number") start = 0;
if(start + search.length > this.length) return false;
else return this.indexOf(search, start) !== -1;
};
}
//Define isContainerElement: This support function will return true if an element can contain text (is not a void element)
(function($){
var visibleVoidElements = ['area','br','embed','hr','img','input','menuitem','track','wbr'];
$.fn.isContainerElement = function(){return ($.inArray($(this).prop("tagName").toLowerCase(), visibleVoidElements) == -1);};
}(jQuery));
//Define Object.keys for old IE
if (!Object.keys) {Object.keys=(function(){'use strict';var hasOwnProperty = Object.prototype.hasOwnProperty,hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),dontEnums = ['toString','toLocaleString','valueOf','hasOwnProperty','isPrototypeOf','propertyIsEnumerable','constructor'],dontEnumsLength = dontEnums.length;return function(obj) {if (typeof obj !== 'function' && (typeof obj !== 'object' || obj === null)) {throw new TypeError('Object.keys called on non-object');}var result = [], prop, i;for (prop in obj) {if (hasOwnProperty.call(obj, prop)) {result.push(prop);}}if (hasDontEnumBug) {for (i = 0; i < dontEnumsLength; i++) {if (hasOwnProperty.call(obj, dontEnums[i])) {result.push(dontEnums[i]);}}}return result;};}());}
//Define Array.indexOf for old IE
if(!Array.prototype.indexOf){Array.prototype.indexOf = function(obj, start){ for (var i = (start || 0), j = this.length; i < j; i++){if (this[i] === obj) { return i; } } return -1;}}
}
}
//This object handles the updating of the ANDI Bar
function AndiBar(){
//This private variable will store the text/html that will appear in the output
var outputText = "";
//This function will add the component to the outputText if it is not empty.
//Parameters:
// accessibleComponentText: text that will appear on the screen as the output
// componentType: component type that will be the class and title attribute
// doMatchingTest: if true, it will run a matching test before attempting to insert the component text, (prevent double speak).
function andiFound(accessibleComponentText, componentType, doMatchingTest){
if(accessibleComponentText !== "" && accessibleComponentText !== undefined && accessibleComponentText != AndiCheck.emptyString){
if(componentType === "legend" || componentType === "parent")//prepend
outputText = "<span class='ANDI508-display-"+componentType+"'>"+accessibleComponentText+"</span> " + outputText;
else if(!doMatchingTest || (doMatchingTest && !matchingTestResult(accessibleComponentText, doMatchingTest)))
outputText += "<span class='ANDI508-display-"+componentType+"'>"+accessibleComponentText+"</span> ";
return true;
}
return false;
//This function will return false if title or aria-describedby text matches a namer's text
//Parameters:
// accessibleComponentText: text of the describer that will be compared for matches
// matchingAgainstObject: the object from which to get the namers text
//TODO: it's possible to throw an alert here, but it would appear in the alert list dynamically on each inspect and you'd have to handle duplication prevention
function matchingTestResult(accessibleComponentText, matchingAgainstObject){
var matchFound = false;
accessibleComponentText = stripHTML(accessibleComponentText); //ignores andiLaser markup
var components = ["ariaLabelledby","ariaLabel","label","alt","innerText","value"];
var text, component;
for(var x=0; x<components.length; x++){
component = components[x];
if(matchingAgainstObject[component] && (component !== "label" || !matchingAgainstObject.ignoreLabel) ){
text = stripHTML(matchingAgainstObject[component]);
if(text !== AndiCheck.emptyString){
if(accessibleComponentText === text)
matchFound = true;
break;
}
}
}
return matchFound;
//This function provides a slick way to remove html and get the inner text
//but also to escape syntax that would throw a javascript error.
//Without the <b> container, it will error out on special characters.
function stripHTML(html){
return $("<b>"+html+"</b>").text();
}
}
}
//This object is used to display the output text if a component has data
this.output = {
//These variables are actually functions. They will be called by the output logic.
//Return false if the component is empty
//Return true if not empty and will add html to the output display.
ariaLabel: function(elementData){return andiFound(elementData.ariaLabel, "aria-label");},
ariaLabelledby: function(elementData){return andiFound(elementData.ariaLabelledby, "aria-labelledby");},
label: function(elementData){return andiFound(elementData.label, "label");},
alt: function(elementData){return andiFound(elementData.alt, "alt");},
value: function(elementData){return andiFound(elementData.value, "value");},
ariaDescribedby:function(elementData){return andiFound(elementData.ariaDescribedby, "aria-describedby", elementData);},
title: function(elementData){return andiFound(elementData.title, "title", elementData);},
summary: function(elementData){return andiFound(elementData.summary, "summary");},
legend: function(elementData){return andiFound(elementData.legend, "legend");},
figcaption: function(elementData){return andiFound(elementData.figcaption, "figcaption");},
caption: function(elementData){return andiFound(elementData.caption, "caption");},
groupingText: function(elementData){return andiFound(elementData.groupingText, "parent");},
//innerText also calls subtree
innerText: function(elementData){
var innerTextResult = andiFound(elementData.innerText, "innerText");
andiFound(elementData.subtree, "child"); //comes after innertext
return innerTextResult;},
addOnProperties:function(elementData){
if(elementData.addOnProperties)
return andiFound(elementData.addOnPropOutput, "addOnProperties");
else return false;}
};
//This function prepares the active element inspection for the next element to display its data
this.prepareActiveElementInspection = function(element){
if(!$(element).hasClass("ANDI508-element-active")){
$("#ANDI508-testPage .ANDI508-element-active").first().removeClass("ANDI508-element-active"); //remove previous active element
$(element).addClass("ANDI508-element-active"); //mark this as the active element that ANDI is inspecting
}
//Display Element Name (tag/role)
var tagNameDisplay = $(element).prop("tagName").toLowerCase();
if($(element).is("input") && $(element).attr("type"))
tagNameDisplay += ' type="' + $(element).attr("type") + '"';
if($(element).attr("role"))
tagNameDisplay += ' role="' + $(element).attr("role") + '"';
$("#ANDI508-elementNameDisplay").html(tagNameDisplay);
//Hide the startUpSummary and show the elementDetails/pageAnalysis
if($("#ANDI508-startUpSummary").html()){
$("#ANDI508-startUpSummary").html("").hide();
$("#ANDI508-elementDetails").css("display","inline-block");
$("#ANDI508-pageAnalysis").show();
}
};
//This function will display the output depending on the logic of the module Output Logic
//which should be defined in each module.
//It will also add the alerts to the output.
//No output will be displayed if there are danger level alerts.
this.displayOutput = function(elementData){
outputText = ""; //reset - this will hold the output text to be displayed
if(elementData.dangers.length){
//dangers were found during load
for(var d=0; d<elementData.dangers.length; d++)
andiFound(elementData.dangers[d],"danger");
}
else{ //No dangers found during load
AndiModule.outputLogic(elementData); //Each module should define this within the inspect logic
}
if(elementData.warnings.length){
//warnings were found during load
for(var w=0; w<elementData.warnings.length; w++)
andiFound(elementData.warnings[w],"warning");
}
if(elementData.cautions.length){
//cautions were found during load
for(var c=0; c<elementData.cautions.length; c++)
andiFound(elementData.cautions[c],"caution");
}
//Place the output display into the container.
$("#ANDI508-outputText").html(outputText);
};
//This function displays the Accessible Components table.
//Only shows components containing data.
//Will display message if no accessible components were found.
this.displayTable = function(elementData, components, addOnPropComponents, additionalComponents){
if(andiCheck.wereComponentsFound(elementData, additionalComponents)){
appendRow(components);
if(elementData.addOnPropertiesTotal !== 0 || additionalComponents)
appendRow(addOnPropComponents, true);
andiLaser.createReferencedComponentLaserTriggers();
}
//This function will append a row to the accessibleComponentsTable if the componentText is not empty
//It will also attach andiLaser functionality if useLaser is true
//Parameters:
// components: array of arrays components to add. each item is an array [0] is the type, [1] is the value
// isAddOnProperty: if true will use addOnProperties as the css class to color the component
function appendRow(components, isAddOnProperty){
var rows = "";
for(var x=0, displayType; x<components.length; x++){
//if this component has a value
if(components[x][1]){
//set display type
displayType = isAddOnProperty ? "addOnProperties" : components[x][0];
//add to row
rows += "<tr id='ANDI508-table-"+components[x][0]+"'><th class='ANDI508-display-"+displayType+"' scope='row'>"+components[x][0]+": </th><td class='ANDI508-display-"+displayType+"'>"+components[x][1]+"</td></tr>";
}
}
if(rows)
$("#ANDI508-accessibleComponentsTable").children("tbody").first().append(rows);
}
};
//This function will focus on an element if it is inspectable according to this module
this.focusIsOnInspectableElement = function(){
//Is there is an active element on the page? (was ANDI was relaunched?)
var activeElement = $("#ANDI508-testPage .ANDI508-element-active").first();
if($(focusedElementAtLaunch).hasClass("ANDI508-element")){
//inspect the element that had focus if it is inspectable by this module
$(focusedElementAtLaunch).focus();
return true;
}
else if(activeElement.length && $(activeElement).hasClass("ANDI508-element")){
//Yes. "re-inspect" the active element
$(activeElement).focus();
return true;
}
else{
$("#ANDI508").focus();
return false; //module logic should show startUpSummary
}
};
//This function will show the startUpSummary with the text provided and conditionally show the pageAnalysis.
//It will also hide the activeElementResults
//Parameters:
// text: text that will appear in the startUpSummary
// showPageAnalysis: if true will show the pageAnalysis
this.showStartUpSummary = function(text,showPageAnalysis,elementType){
var instruction = "";
if(elementType)
instruction = "<p>Determine if the ANDI Output conveys a complete and meaningful contextual equivalent for every "+elementType+".</p>";
text = "<p>"+text+"</p>";
if(showPageAnalysis)
$("#ANDI508-pageAnalysis").show();
else
$("#ANDI508-pageAnalysis").hide();
$("#ANDI508-elementDetails").hide();
$("#ANDI508-startUpSummary").html(text+instruction).css("display","inline-block");
};
//This function updates the resultsSummary
//Parameters:
// summary: the summary text
this.updateResultsSummary = function(summary){
$("#ANDI508-resultsSummary-heading").html(summary);
};
//These functions show/hide the elementControls
this.showElementControls = function(){
$("#ANDI508-elementControls button").show();
};
this.hideElementControls = function(){
$("#ANDI508-elementControls button").hide();
};
this.showModuleLoading = function(){
$("#ANDI508-body").hide();
$("#ANDI508-loading").css("display","inline-block");
};
this.hideModuleLoading = function(){
setTimeout(function(){
$("#ANDI508-loading").hide();
$("#ANDI508-body").show();
},1);
};
}
//This class is used to reset things that ANDI changed.
function AndiResetter(){
//This function will clean up almost everything that ANDI inserted.
//Exceptions: .ANDI508-element-active (handled on close button press)