1rosehip / jplist

jPList jQuery Data Grid Controls is a flexible jQuery plugin for sorting, pagination and filtering of any HTML structure (DIVs, UL/LI, tables, etc).
http://jplist.com
Other
436 stars 177 forks source link

Animate-to-top fires on plugin initialisation should only fire on first interaction with the controls? #255

Open mistyn8 opened 7 years ago

mistyn8 commented 7 years ago

if the jplist pagination plugin affects content that is below the fold, eg outside of the viewport then the page will auto scroll on load if animate-to-top is true.

really we want the page to load, stay top 0px and animate-to-top only occurs if the user interacts with the pagination say..

I can't see an easy way to see that the status is the initiation event and not a subsequent user interaction to allow for this.

mistyn8 commented 7 years ago
    /**
     * animate to top
     * @param {*} context
     * @param {Array.<jQuery.fn.jplist.StatusDTO>} statuses
     */
    var animateToTop = function(context, statuses){

        var offset
            ,shouldAnimate = false;

        if(statuses){

            for(var i=0; i<statuses.length; i++){

                if(statuses[i].isAnimateToTop){

                    shouldAnimate = true;
                    break;
                }
            }

            if(shouldAnimate){

                //set offset
                offset = jQuery(context.options.animateToTop).offset().top;

                jQuery('html, body').animate({
                    scrollTop: offset
                }, context.options.animateToTopDuration);
            }
        }
    };

updated if(statuses[i].isAnimateToTop){ to if (statuses[i].isAnimateToTop && context.history.listStatusesQueue.length > 1) {

seems to do the trick