From 665f34b67e6db8fe6f35d383d79f1142e6d0a6ea Mon Sep 17 00:00:00 2001 From: Gerard Date: Wed, 6 Mar 2019 11:05:29 +0100 Subject: [PATCH] #1216 uvc now deletes the styles when you change the state --- front/core/directives/uvc.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/front/core/directives/uvc.js b/front/core/directives/uvc.js index 45e04a27b..c881cf545 100644 --- a/front/core/directives/uvc.js +++ b/front/core/directives/uvc.js @@ -49,13 +49,26 @@ export function directive($http, $compile, vnApp, $translate) { } }); - let rule = selectors.join(', ') + '{display: none;}'; - if ($scope.css) - document.head.removeChild($scope.css); - $scope.css = document.createElement('style'); - document.head.appendChild($scope.css); - $scope.css.appendChild(document.createTextNode(rule)); + if ($scope.css || document.querySelector('style[id="uvc"]')) { + let child = document.querySelector('style[id="uvc"]'); + child.parentNode.removeChild(child); + } + + if (selectors.length) { + let rule = selectors.join(', ') + '{display: none;}'; + $scope.css = document.createElement('style'); + $scope.css.setAttribute('id', 'uvc'); + document.head.appendChild($scope.css); + $scope.css.appendChild(document.createTextNode(rule)); + } + + $scope.$on('$destroy', () => { + if ($scope.css && document.querySelector('style[id="uvc"]')) { + let child = document.querySelector('style[id="uvc"]'); + child.parentNode.removeChild(child); + } + }); } function saveConfiguration(tableConfiguration) {