From 7c2f4adfd5433a171654af62ed279d11a62503dc Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Thu, 2 Sep 2021 13:52:37 +0100 Subject: [PATCH] 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 --- .../partials/area-map-javascripts.html | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/templates/views/broadcast/partials/area-map-javascripts.html b/app/templates/views/broadcast/partials/area-map-javascripts.html index 79eabbde6..fdb7af5f7 100644 --- a/app/templates/views/broadcast/partials/area-map-javascripts.html +++ b/app/templates/views/broadcast/partials/area-map-javascripts.html @@ -46,13 +46,11 @@ function addAriaLabel (mapElement) { function getLabelPrefix (areas) { - var labelPrefix = ['Map of the United Kingdom, showing the ', ' for']; - - if (areas.length === 1) { - return labelPrefix[0] + 'area' + labelPrefix[1]; - } else { - return labelPrefix[0] + 'areas' + labelPrefix[1]; - } + return [ + 'Map of the United Kingdom, showing the ', + (areas.length === 1) ? 'area' : 'areas', + ' for' + ].join(''); }; function getStringOfAreas (areas) { @@ -63,10 +61,11 @@ function getAreaName (area) { var areaString = ''; var childNodesLen = area.childNodes.length; + var idx; var childNode; - while (childNodesLen--) { - childNode = area.childNodes[childNodesLen]; + for (idx = 0; idx < childNodesLen; idx++) { + childNode = area.childNodes[idx]; if (childNode.nodeType === 3) { areaString += childNode.nodeValue; } // only use text nodes }