mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 10:28:41 -04:00
Refactor JS
Based on these comments on the associated pull request: - add area/areas condition to the array used to build the label prefix https://github.com/alphagov/notifications-admin/commit/e2af2f63a41e48ce51fc4be3beb5893049e5d3b6#r55831534 - use a for loop instead of while when looping through nodes https://github.com/alphagov/notifications-admin/commit/e2af2f63a41e48ce51fc4be3beb5893049e5d3b6#r55831693
This commit is contained in:
@@ -46,13 +46,11 @@
|
|||||||
function addAriaLabel (mapElement) {
|
function addAriaLabel (mapElement) {
|
||||||
|
|
||||||
function getLabelPrefix (areas) {
|
function getLabelPrefix (areas) {
|
||||||
var labelPrefix = ['Map of the United Kingdom, showing the ', ' for'];
|
return [
|
||||||
|
'Map of the United Kingdom, showing the ',
|
||||||
if (areas.length === 1) {
|
(areas.length === 1) ? 'area' : 'areas',
|
||||||
return labelPrefix[0] + 'area' + labelPrefix[1];
|
' for'
|
||||||
} else {
|
].join('');
|
||||||
return labelPrefix[0] + 'areas' + labelPrefix[1];
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getStringOfAreas (areas) {
|
function getStringOfAreas (areas) {
|
||||||
@@ -63,10 +61,11 @@
|
|||||||
function getAreaName (area) {
|
function getAreaName (area) {
|
||||||
var areaString = '';
|
var areaString = '';
|
||||||
var childNodesLen = area.childNodes.length;
|
var childNodesLen = area.childNodes.length;
|
||||||
|
var idx;
|
||||||
var childNode;
|
var childNode;
|
||||||
|
|
||||||
while (childNodesLen--) {
|
for (idx = 0; idx < childNodesLen; idx++) {
|
||||||
childNode = area.childNodes[childNodesLen];
|
childNode = area.childNodes[idx];
|
||||||
if (childNode.nodeType === 3) { areaString += childNode.nodeValue; } // only use text nodes
|
if (childNode.nodeType === 3) { areaString += childNode.nodeValue; } // only use text nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user