From 613727a0a029b56c57b50cdf0c1ddd888b298df9 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sun, 6 Nov 2016 19:56:28 +0100 Subject: [PATCH] Make marker z-index rotation more functional-style --- extension/lib/marker-container.coffee | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/extension/lib/marker-container.coffee b/extension/lib/marker-container.coffee index a12c0c6..b6a0824 100644 --- a/extension/lib/marker-container.coffee +++ b/extension/lib/marker-container.coffee @@ -432,14 +432,17 @@ rotateOverlappingMarkers = (originalMarkers, forward) -> return a.markerElement.style.zIndex - b.markerElement.style.zIndex ) - zIndices = (marker.markerElement.style.zIndex for marker in stack) + [first, middle..., last] = + (marker.markerElement.style.zIndex for marker in stack) + # Shift the `z-index`:es one item forward or back. The higher the `z-index`, # the more important the element. `forward` should give the next-most # important element the best `z-index` and so on. - if forward - zIndices.push(zIndices.shift()) - else - zIndices.unshift(zIndices.pop()) + zIndices = + if forward + [middle..., last, first] + else + [last, first, middle...] for marker, index in stack marker.markerElement.style.zIndex = zIndices[index] -- 2.39.3