Skip to content

Commit

Permalink
Rewrite select all using MutationObserver instead of DOMSubtreeModifi…
Browse files Browse the repository at this point in the history
…ed (dropped by Chrome).
  • Loading branch information
cbeer committed Sep 11, 2024
1 parent 69b0fa4 commit 78af604
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions app/javascript/select-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 78af604

Please sign in to comment.