Skip to content

prev() method not working #134

@annuh

Description

@annuh

Hello,
First of all thank you for this great plugin!

I am using the history plugin and would like to extend this plugin to scroll the page to the last clicked item. This works perfectly if the last clicked item is on the last loading page.
However, it is possible that this plugin has already loading (for example) page 4 while the users clicks an item on page 3.
To overcome this problem I would like to load the previous page automatically. The documentation states that the .prev() method (http://infiniteajaxscroll.com/docs/extension-history.html) should load the previous page, but this doesn't work for me.

I have also tried to execute the commands in the console:

$.ias().next(); // returns true;
$.ias().prev(); // returns undefined??

So far I have the following code. Could you tell me what I am doing wrong? :)
Thank you!

var ias = $.ias({
    container: '#cards-list',
    item: '.card-wrapper',
    pagination: '.pagination-bs',
    next: '.next'
});
ias.extension(new IASSpinnerExtension({
    html: $('.cards-loading-container').html(),
}));
ias.extension(new IASTriggerExtension({
    offset: 5,
    html: $('.cards-more-block-container').html(),
}));
ias.extension(new IASPagingExtension());
ias.extension(new IASHistoryExtension()); // Previous button has class 'prev'
ias.on('ready', function () {
    var id = window.location.hash.substr(1);
    if (id) {
        // Check if card is visible on current page
        var element = 'li#card-' + id;
        if (!$(element).length) {
            ias.on('rendered', function (items) {
                scrollTo(element);
            });
            ias.prev(); // Load previous page; not working :(
        } else {
            scrollTo(element);
        }
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions