RobertFischer / JQuery-PeriodicalUpdater

A port of Prototype's PeriodicalUpdater to JQuery
282 stars 50 forks source link

Fix enqueuing of periodic call when jquery-cookie plugin is already included on the page and cookie option is unspecified. #30

Closed Umofomia closed 10 years ago

Umofomia commented 11 years ago

This is a pretty simple fix for an issue that happens in the following case:

When these two occurred, the call would not be enqueued for periodic updating.

The cause for the bug was due to the first line here:

} else if($.cookie && $.cookie(settings.cookie.name)) {
    // Do nothing (already handled above)
} else {
    pu_log("Enqueing a the call for after " + timerInterval, 1);
    reset_timer(timerInterval);
}

Because $.cookie exists, it will attempt to call $.cookie(settings.cookie.name), but because settings.cookie was not specified, it calls $.cookie() with an undefined value, which ends up returning all cookies. As a result it ends up going into the // Do nothing block instead of enqueuing the call.

This fix changes the if statement to also check that settings.cookie was specified first:

} else if(settings.cookie && $.cookie && $.cookie(settings.cookie.name)) {