Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add event listener to uncheck sendPost checkbox when the Publis…
Browse files Browse the repository at this point in the history
…h button is clicked

Potential concerns with this approach:

- A wait is needed, otherwise the notification won't send. This may because it takes the plugin time to structure the request and immediately unchecking it will mark it as "don't send". Generally, functionality should not be dependent on waiting
- The publish is targeted from the document body (`.editor-post-publish-button__button`) but this is brittle since we don't control the class values on the button
sherwinski committed Jan 15, 2025
1 parent ea4b70d commit 6309413
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions v3/onesignal-metabox/onesignal-metabox.js
Original file line number Diff line number Diff line change
@@ -32,4 +32,25 @@ window.addEventListener("DOMContentLoaded", () => {
setDisplay(customiseWrap, customisePost.checked);
setDisabled(customiseWrapChild, !customisePost.checked);
});

// Watch for the Publish button to be added to the DOM
const observer = new MutationObserver((mutations, obs) => {
const publishButton = document.querySelector('.editor-post-publish-button__button');

if (publishButton) {
publishButton.addEventListener('click', function() {
setTimeout(() => {
if (sendPost && sendPost.checked) {
sendPost.click();
}
}, 1000);
});
obs.disconnect(); // Stop observing once we've found and handled the button
}
});

observer.observe(document.body, {
childList: true,
subtree: true
});
});

0 comments on commit 6309413

Please sign in to comment.