Skip to content

Commit

Permalink
Remove deprecated DOMNodeInserted
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdoderlein committed Sep 10, 2024
1 parent cf9cf83 commit b827eb2
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,36 @@ <h4>Graphics main window</h4>
}, false);

// Loading Animation
$('body').on('DOMNodeInserted', 'pre', function () {
$('#loader-wrapper').addClass("tester")
});
// Select the body element
var targetNode = document.querySelector('body');

// Options for the observer (which mutations to observe)
var config = { childList: true, subtree: true };

// Callback function to execute when mutations are observed
var callback = function(mutationsList, observer) {
mutationsList.forEach(function(mutation) {
// Check if any new nodes are added
mutation.addedNodes.forEach(function(node) {
// If the added node is a <pre> element
if (node.nodeName === 'SPAN' && node.classList.contains("stdout")) {
// Add the class 'tester' to #loader-wrapper
document.querySelector('#loader-wrapper').classList.add("tester");
}
});
});
};

// Create an observer instance linked to the callback function
var observer = new MutationObserver(callback);

// Start observing the target node for configured mutations
observer.observe(targetNode, config);

document.getElementById("loader-wrapper").addEventListener("animationend", (ev) => {
if (ev.type === "animationend") {
document.getElementById("loader-wrapper").style.display = "none";
$('body').off('DOMNodeInserted');
observer.disconnect();
if (autosave_number() > 0) {
if (confirm("Des documents ont été sauvegardé automatiquement lors de la dernière session, voulez vous les restaurer ?")) {
restore_editors();
Expand Down

0 comments on commit b827eb2

Please sign in to comment.