Intro.js skips steps on page load when there is no cookie

692 Views Asked by At

Using the below code, when the page loads and there is no cookie, the condition is met and

Walkthrough.runWalkthrough();

is executed. The intro.js walkthrough starts but it skips steps, it will go from step 1,3,6. When I refresh the cookie is still stored and running Walkthrough.runWalkthrough(); launches the walkthrough with all functionality in tact. Wondering how to get around this issue?

getData: function(setting) {
Walkthrough.setting = setting;
$.getJSON("/account/walkthrough", function(data) {
    Walkthrough['info'] = data['steps'][setting];
}).done(function(data) {
    if (!Walkthrough.getCookie(Walkthrough['lookup'][setting])) {

         Walkthrough.runWalkthrough();

    }
});

My theory is the IF statement is the cause of the issue because when the IF statement is removed the walkthrough starts with no issues, only when its wrapped inside the IF are steps being skipped. Wondering why?

1

There are 1 best solutions below

0
On BEST ANSWER

The problem was the if statement was conflicting with an if statement in another part of the code that was executing the same function. By removing the other function that sets the cookie and adding a step for cookie setting inside the conditional shown above, the problem was eliminated and the code became more cohesive as well.