https://www.skycandyaustin.com/class/open-studio/
Here you can see the Waitlist Button on Thursday, October 25. Requirement is if the class is full, then display Waitlist instead of button and I did that. Here below is the code for the same.
$("div.bw-session:has(span.hc_waitlist)").each(function () {
$(this).find(".bw-widget__signup-now").hide();
$("span.bw-widget__cart_button", this).append("<a class=\"hc-button signup_now bw-widget__signup-now bw-widget__cta\" href=\"mailto:"
+ scConfig.waitlistEmail + "?subject=Waitlist for "
+ $('div.bw-session__name', this).text().replace(reWhitespace, ' ')
+ '&body=Hello%2c %0D%0A %0D%0A Please add me to the Waitlist for '
+ $('div.bw-session__name', this).text().replace(reWhitespace, ' ')
+ " on " + $(this).parent().children('.bw-widget__date').text().replace(/,/g, "")
+ " with " + $("div.bw-session__staff", this).text()
+ ".\">Waitlist</a>");
});
Then I used DOM MutationObserver, but the issue I am facing right now is if you check the inspect element you can see anchor class is appending every 1 sec. Here is the code for the same. I just need to append the element once. So can you please help me to fix the issue?
// Observer way to listen for changes
// Create an observer instance
var observer = new MutationObserver(function (mutations) {
if (mutatingWidget === false) {
if (mutationTimer > 0) {
window.clearTimeout(mutationTimer);
}
mutationTimer = window.setTimeout(postWidgetLoad, 1000);
}
});
// Configuration of the observer:
var config = { attributes: true, childList: true, subtree: true };
// Pass in the target node, as well as the observer options
$("healcode-widget").each(function () {
console.debug("Observing changes on " + this.tagName);
observer.observe(this, config);
});
Found the solution after hours of code research. I gave a check where the postWidgetLoad is calling using setTimeout.
Here is the logic applied.
Since i am appending new class hc-button for waitlist section, checked whether the class exists or not. If not then call the postWidgetLoad function, otherwise the loop will stop executing, since the class has been already created.