From a14cb42e1c6f42c378ea372067dd5e0ddcf3b8b5 Mon Sep 17 00:00:00 2001 From: J Scott Smith Date: Wed, 20 Sep 2017 17:53:12 -0700 Subject: [PATCH] use findIndex in removeElement(), guard for elements that are not found in updateElement() --- src/libs/ParallaxController.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libs/ParallaxController.js b/src/libs/ParallaxController.js index 065b150dc..7d05b44f1 100644 --- a/src/libs/ParallaxController.js +++ b/src/libs/ParallaxController.js @@ -340,7 +340,9 @@ function ParallaxController() { * @param {object} element */ this.removeElement = function(element) { - const index = elements.indexOf(element); + // gets the index of the element to update based on id + const index = elements.findIndex(el => el.id === element.id); + if (index !== -1) { elements.splice(index, 1); } @@ -356,10 +358,12 @@ function ParallaxController() { const index = elements.findIndex(el => el.id === element.id); // create new element with options and replaces the old - elements[index] = Object.assign({}, elements[index], options); + if (index !== -1) { + elements[index] = Object.assign({}, elements[index], options); - // call update to set attributes and positions based on the new options - this.update(); + // call update to set attributes and positions based on the new options + this.update(); + } }; /**