Search code examples
javascriptjquerywordpresspjaxrevolution-slider

Slider Revolution + BarbaJS (PJAX)


I'm trying to get Slider Revolution sliders to reinitialize within BarbaJS.

I'm currently setting up functions originally notated by ThemePunch's documentation:

// RevSlider
function getCurrentSliderAPI() {
    var slider = jQuery('.rev_slider');
    if(!slider.length) return false;
    return eval('revapi' + slider.attr('id').split('rev_slider_')[1].split('_')[0]);
}
// Start RevSlider
function startSlider() {
    var revapi = getCurrentSliderAPI();
    if(revapi) {
        revapi.revstart();
        console.log('Slider ' + revapi + ' started.');
    }
}
// Kill RevSlider
function killSlider() {
    var revapi = getCurrentSliderAPI();
    if(revapi) {
        revapi.revkill();
        console.log('Slider ' + revapi + ' killed.');
        revapi = null;
    }   
}

The getCurrentSliderAPI function seems to have issues. I set console logs in order to make sure that function is actually working in the other two functions, to no avail.

With this current set up, I have this console error: revapi1 is not defined upon loading into the page from another with the slider activated.

Any help in getting the Revolution Slider to initialize on page transitions would be very helpful. Thanks.


Solution

  • https://stackoverflow.com/a/25191095/4220832

    This looks to be the answer to the issue I need, even though it's about the jQuery version. I would have to place the slider inside of an iframe in order to get it to reinitialize, since it removes the iframe and reloads it in a new one. This isn't ideal to use iframes, but it reduces the memory leak issue as well.