From 78af604192ac1c93161d5d42f4664b1cd68f0c83 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 11 Sep 2024 08:57:27 -0700 Subject: [PATCH] Rewrite select all using MutationObserver instead of DOMSubtreeModified (dropped by Chrome). --- app/javascript/select-all.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/javascript/select-all.js b/app/javascript/select-all.js index b0e4d4607..c89cb0e5e 100644 --- a/app/javascript/select-all.js +++ b/app/javascript/select-all.js @@ -22,21 +22,30 @@ $element.on('click', function() { var state = $selectAll.is(':visible'); bookmarkSelectors = $(selectorSelectBookmarks); - var first = false; + var first = true; var firstCheckboxIsDone = new $.Deferred(); + var observer = new MutationObserver(function(mutationList) { + for (const mutation of mutationList) { + mutation.addedNodes.forEach(function(node) { + if (node.text != 'Saving...') { + firstCheckboxIsDone.resolve(); + } + }); + } + }); + bookmarkSelectors.each(function(i, checkbox) { - if (!first){ + if (first) { var $checkbox = $(checkbox); if ($checkbox.is(':checked') !== state) { - var span = $checkbox.next('span'); - first = true; + first = false; + var span = $checkbox.next('span'); + observer.observe(span[0], { childList: true, subtree: true }); $checkbox.prop('checked', !state).click(); - span.on('DOMSubtreeModified', function(){ - firstCheckboxIsDone.resolve(); - }); } } }); + $.when(firstCheckboxIsDone).done(function(){ bookmarkSelectors.each(async function(i, checkbox) { var $checkbox = $(checkbox);