SSAgov / ANDI

A tool to test web content for accessibility and 508 compliance.
https://www.ssa.gov/accessibility/andi/help/howtouse.html
Other
293 stars 75 forks source link

id in the overlayTableMarkup function could be found by using the .attr() function #209

Closed ollie-iterators closed 1 year ago

ollie-iterators commented 1 year ago

The id value in the overlayTableMarkup function could be found by using the .attr() function.

This would allow the code to be condensed to use a for loop with a list containing the attributes that are being looked for.

JohnCotterSSA commented 1 year ago

Thanks for looking into the code and making a recommendation.

This function already is a loop, and .id performs faster than jquery .attr()

ollie-iterators commented 1 year ago

I'm talking about "AndiOverlay.prototype.overlayTableMarkup" in line 1533. The for loop would replace the if statements: "if(role)", "if(id)", "if(headers)", and "if(scope)".

ollie-iterators commented 1 year ago

Difference in the code:

Original Code ""

scope = $(this).attr("scope"); headers = $(this).attr("headers"); id = this.id; role = $(this).attr("role");

markupOverlay = $(this).prop("tagName").toLowerCase();

if(role) markupOverlay += " role=" + role; if(id) markupOverlay += " id=" + id; if(headers) markupOverlay += " headers=" + headers; if(scope) markupOverlay += " scope=" + scope;

New Code

NOTE: markupOverlay would be moved out of the $("#ANDI508-testPage [data-tandi508-colindex]").each(function() area

var attributesToFind = ["scope", "headers", "id", "role"]; for (var a = 0; a < attributesToFind.length; a++) { var attributeValue = $(this).attr(attributesToFind[a]); if (attributeValue) { markupOverlay += attributesToFind[a] + "=" + attributeValue; } }