Developer forum

Forum » Rapido » Expand.js bug in ajaxContainer.addEventListener

Expand.js bug in ajaxContainer.addEventListener

Mafalda Correa
Mafalda Correa
Reply

Hi,

I was using the Expand.js function to create an accordion on the search page and I came across a bug in the function.

The funcion loops through all the .js-handlebars-root, but only adds the EventListener to the last.

See the video here:

https://www.screencast.com/t/TPqYz78o

This is how I solved the issue:

document.addEventListener("DOMContentLoaded", function (event) {
    if (RememberState == null) {
        Expand.initExpandTriggers();
    }

    //Make it work with Ajax loaded content
    var ajaxContainer = document.getElementsByClassName("js-handlebars-root");
    if (ajaxContainer.length > 0) {
        for (var i = 0; i < ajaxContainer.length; i++) {
            ajaxContainer[i].addEventListener('contentLoaded', function (e) {
                Expand.initExpandTriggers(this); // <----- bug fix in this line
            }, false);
        }
    }
});

Replies

 
Olga Shedko Dynamicweb Employee
Olga Shedko
Reply

Hello Mafalda,

Nice found, thank you very much! The new TFS # 72715 has been created for solving this issue to the next hot-fix release.

Best regards,

Olga | QA

 

You must be logged in to post in the forum