From 65d065fb549b16fed6b3631ddaf39b53683e7197 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Wed, 21 Sep 2022 14:59:54 +0200 Subject: [PATCH 1/2] add an extra check to ensure the pips exist before adding a class to them --- .../common/directives/components/umbrangeslider.directive.js | 5 ++++- .../src/installer/steps/user.controller.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbrangeslider.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbrangeslider.directive.js index 0c46ada020..9d9c6a3421 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbrangeslider.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbrangeslider.directive.js @@ -332,7 +332,10 @@ For extra details about options and events take a look here: https://refreshless activePip[handle] = pip; } }); - activePip[handle].classList.add("noUi-value-active"); + + if (activePip[handle]) { + activePip[handle].classList.add("noUi-value-active"); + } }); } function addPipClickHandler(){ diff --git a/src/Umbraco.Web.UI.Client/src/installer/steps/user.controller.js b/src/Umbraco.Web.UI.Client/src/installer/steps/user.controller.js index e65499ba6b..a8bb36d3d5 100644 --- a/src/Umbraco.Web.UI.Client/src/installer/steps/user.controller.js +++ b/src/Umbraco.Web.UI.Client/src/installer/steps/user.controller.js @@ -64,7 +64,10 @@ angular.module("umbraco.install").controller("Umbraco.Install.UserController", f activePip[handle] = pip; } }); - activePip[handle].classList.add("noUi-value-active"); + + if (activePip[handle]) { + activePip[handle].classList.add("noUi-value-active"); + } }); $(consentSlider).on('$destroy', function () { From 348f3e71eafe07f22b2b6efe1d37bfcc47fe5d65 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Wed, 21 Sep 2022 15:37:57 +0200 Subject: [PATCH 2/2] improve pip classList add/remove with no intermediary variable --- .../directives/components/umbrangeslider.directive.js | 11 ++--------- .../src/installer/steps/user.controller.js | 11 ++--------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbrangeslider.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbrangeslider.directive.js index 9d9c6a3421..405641a9ab 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbrangeslider.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbrangeslider.directive.js @@ -322,20 +322,13 @@ For extra details about options and events take a look here: https://refreshless }); } function setUpActivePipsHandling() { - let activePip = [null, null]; sliderInstance.noUiSlider.on('update', function (values,handle) { - if(activePip[handle]){ - activePip[handle].classList.remove("noUi-value-active"); - } sliderInstance.querySelectorAll('.noUi-value').forEach(pip => { + pip.classList.remove("noUi-value-active"); if (Number(values[handle]) === Number(pip.getAttribute('data-value'))) { - activePip[handle] = pip; + pip.classList.add("noUi-value-active"); } }); - - if (activePip[handle]) { - activePip[handle].classList.add("noUi-value-active"); - } }); } function addPipClickHandler(){ diff --git a/src/Umbraco.Web.UI.Client/src/installer/steps/user.controller.js b/src/Umbraco.Web.UI.Client/src/installer/steps/user.controller.js index a8bb36d3d5..4726a53aaf 100644 --- a/src/Umbraco.Web.UI.Client/src/installer/steps/user.controller.js +++ b/src/Umbraco.Web.UI.Client/src/installer/steps/user.controller.js @@ -54,20 +54,13 @@ angular.module("umbraco.install").controller("Umbraco.Install.UserController", f const pips = consentSlider.querySelectorAll('.noUi-value'); - let activePip = [null, null]; consentSlider.noUiSlider.on('update', function (values,handle) { - if(activePip[handle]){ - activePip[handle].classList.remove("noUi-value-active"); - } consentSlider.querySelectorAll('.noUi-value').forEach(pip => { + pip.classList.remove("noUi-value-active"); if (Number(values[handle]) === Number(pip.getAttribute('data-value'))) { - activePip[handle] = pip; + pip.classList.add("noUi-value-active"); } }); - - if (activePip[handle]) { - activePip[handle].classList.add("noUi-value-active"); - } }); $(consentSlider).on('$destroy', function () {