Skip to content

Commit

Permalink
fix DOMNodeInserted to MutationObserver and renew excel dropdown on m…
Browse files Browse the repository at this point in the history
…utation public tests
  • Loading branch information
schefbi committed Jul 30, 2024
1 parent 7e6a643 commit fa6d2e2
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions public/apps/MasterExcel/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,42 +72,44 @@ 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 + '<a onclick="X.showOverlay(4,'+ i +')";>' + test + '</a>';
}
});

// 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 = '<button id="overlay-toggle-embedded-test" type="button" class="btn btn-outline-primary ms-2 dropdown-toggle excelDropdown">\
<span>' + X.strings[getLanguage()].views[2].start_dropdown + ' </span>\
<div class="excelDropdown-content">'
+dropdownItems+
'</div> </button>';


if(document.getElementsByClassName('desktop').length > 0) {
var buttons = $(buttons_html);
$('#excel-import').append(buttons);
}

}


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});

0 comments on commit fa6d2e2

Please sign in to comment.