From a6f39c08de4bba9dc327b82800b38784e813a1bf Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Fri, 26 Apr 2019 19:21:34 +0100 Subject: [PATCH] Dedupe list-entry shared attributes The `getSharedAttributes` method gathers all attributes, and [DOM tokens](https://developer.mozilla.org/en-US/docs/Web/API/Element/classList) in the `class` attribute not controlled by the module for re-applying in the `render` method. Because it gathered them for all items, many duplicates ended up being added to new items. Browser engines were tidying up the duplicates but we shouldn't be adding them in the first place. --- app/assets/javascripts/listEntry.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/listEntry.js b/app/assets/javascripts/listEntry.js index 938a0a121..b5dd7c88e 100644 --- a/app/assets/javascripts/listEntry.js +++ b/app/assets/javascripts/listEntry.js @@ -58,6 +58,7 @@ getAttributesHTML = function (attrsByElm) { var attrStr = '', elmIdx = attrsByElm.length, + existingAttributes = [], elmAttrs, attrIdx; @@ -65,7 +66,11 @@ elmAttrs = attrsByElm[elmIdx]; attrIdx = elmAttrs.length; while (attrIdx--) { - attrStr += attributeTemplate.render({ 'name': elmAttrs[attrIdx].name, 'value': elmAttrs[attrIdx].value }); + // prevent duplicates + if ($.inArray(elmAttrs[attrIdx].name, existingAttributes) === -1) { + attrStr += attributeTemplate.render({ 'name': elmAttrs[attrIdx].name, 'value': elmAttrs[attrIdx].value }); + existingAttributes.push(elmAttrs[attrIdx].name); + } } } return attrStr;