jqueryendlessscroll

How to call ceaseFire in jquery endless scroll


var lazyLoadList = {
  zeroResult:'',
  loadList:function(url,templateName,callbackaction,divId){
        this.zeroResult = false;
        $(document).endlessScroll({
            //pagesToKeep: 10,
            fireOnce: false,
            callback: callbackaction,
            ajaxUrl: url,
            templateName: templateName,
            divIdToUpdate: divId,
            ceaseFireOnEmpty:true,
            ceaseFire: function(i, p) {
               return this.zeroResult;
            }, 
            intervalFrequency: 5
        });
    },
   getlist:function(fireSequence, pageSequence, scrollDirection, ajaxUrl, templateName, divIdToUpdate){


        if (pageSequence > 1) {
            var requestUrl = ajaxUrl + pageSequence;
            $.ajax({
                url: requestUrl,
                dataType: 'json',
                complete: function() {
                },
                success: function(response){
                   if (response != '0'){
                        var template = $("#"+templateName).html();
                        detailView = Mustache.render(template, response.data);

                        $("#"+divIdToUpdate).append(detailView);
                        //serviceListTemplateDiv
                    }else{
                        this.zeroResult = true;
                    }
                }
            });
         }
     }  

};

In the above code I am jQuery endless scroll plugin. I have two questions regarding the above code:-

1- How to call ceaseFire when this.zeroResult is true?

2- How to stop callback when scrolled in upward direction, like I have handled this using if (pageSequence > 1) {} in the above code?


Solution

  • Use lazyLoadList.zeroResult instead of this.zeroResult
    

    Class names are important and should be used to call/ access variables and methods