Instantiate your own Mutation Observer in Ascend

Pattern

The following pattern can be used to instantiate your own Mutation Observer in the Always Execute section of your experiments in Ascend:

(function(window){

// select the target node
var target = document.querySelector("#chat-container");

// create an observer instance
var observer = new MutationObserver(function(mutations) {

var chatCTA = document.querySelector("button[data-test='chat-submit-message']");

if(chatCTA){

$(chatCTA).click(function(){ window.ascend.trigger(); });

$("#widgetInputCarcodeWidget").keypress(function(e) { if(e.which == 13) { window.ascend.trigger(); } });

observer.disconnect();

}

});

// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true, subtree: true };

// pass in the target node, as well as the observer options
observer.observe(target, config);


})(window);

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk