From fa6d2e20fa724ccd9f43f879f36ea4e4b85bf171 Mon Sep 17 00:00:00 2001 From: schefbi Date: Tue, 30 Jul 2024 13:50:27 +0200 Subject: [PATCH] fix DOMNodeInserted to MutationObserver and renew excel dropdown on mutation public tests --- public/apps/MasterExcel/main.js | 36 +++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/public/apps/MasterExcel/main.js b/public/apps/MasterExcel/main.js index 21a840ef..7e185912 100644 --- a/public/apps/MasterExcel/main.js +++ b/public/apps/MasterExcel/main.js @@ -72,23 +72,24 @@ function insertButtonsTest() { return; } - - // die Buttons nur einfügen, wenn sie nicht bereits da sind - if ($('#overlay-toggle-embedded-test').length === 1) { - return; - } - + var tests = X.collectTestNames(); var dropdownItems = ''; - var tests = X.collectTestNames(); - - var i = 0 + var i = 1 tests.forEach(test => { if (dropdownItems.indexOf(test) === -1 && tests.indexOf(test) > 0 && test.length > 0) { i++ dropdownItems = dropdownItems + '' + test + ''; } }); + + // Falls sie vorhanden sind neu einfügen. Damit kann der useCase gelöst werden, falls ein Test publiziert wird das dieser nicht mehr dargestellt wird und umgekehrt. + var testslinks = $('#overlay-toggle-embedded-test div').first().children().length+1; + if (testslinks != i) { + $('#excel-import').empty(); + } else { + return; + } var buttons_html = ''; - if(document.getElementsByClassName('desktop').length > 0) { var buttons = $(buttons_html); $('#excel-import').append(buttons); @@ -104,10 +104,12 @@ function insertButtonsTest() { } - -window.addEventListener("DOMNodeInserted", function (ev) { - setTimeout(function(){ - insertButtonsGrading(); - insertButtonsTest(); - },200); -}, false); +const observer = new MutationObserver(mutationList => + mutationList.filter(m => m.type === 'childList').forEach(m => { + setTimeout(function(){ + insertButtonsGrading(); + insertButtonsTest(); + },200); + + })); +observer.observe(window.document,{childList: true, subtree: true}); \ No newline at end of file