From 08b52a0ef8e6cf5807fea67b2201cc74e0e566f6 Mon Sep 17 00:00:00 2001 From: Stefan Galinski <stefan@sgalinski.de> Date: Wed, 20 Jul 2016 20:47:00 +0200 Subject: [PATCH] [BUGFIX] Next news not loaded if there is no scrollbar --- Resources/Public/Scripts/ScrollBrowser.js | 82 ++++++++++++----------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/Resources/Public/Scripts/ScrollBrowser.js b/Resources/Public/Scripts/ScrollBrowser.js index 9b45a2a..01e48be 100644 --- a/Resources/Public/Scripts/ScrollBrowser.js +++ b/Resources/Public/Scripts/ScrollBrowser.js @@ -67,44 +67,50 @@ SG.ElementScrollBrowser.prototype = { } this.url = $('.tx-pagebrowse-next a').attr('href'); - $(window).on( - 'scroll', function() { - var recordLockedOrNotInPosition = this.lock || !this.checkPosition(); - var urlIsInvalid = typeof this.url === 'undefined' || this.url === this.lastUrl; - if (recordLockedOrNotInPosition || urlIsInvalid) { - return; - } - - this.lock = true; - $.ajax( - { - url: this.url, - - success: function(response) { - var results = $(response).find('.tx-sgnews-list'); - results.each(function(index, result) { - var $result = $(result); - var children = $result.children(); - if (!children.length) { - return; - } - - var $resultList = $('.tx-sgnews-list-' + $result.data('category')); - if (!$resultList.length) { - $resultList = $('.tx-sgnews-list'); - } - $resultList.append(children); - - this.loadIndicator = $resultList.children(':last'); - }); - - this.lastUrl = this.url; - this.url = $(response).find('.tx-pagebrowse-next a').attr('href'); - this.lock = false; - }.bind(this) - } - ); - }.bind(this) + $(window).on('scroll', this.checkAndLoad.bind(this)); + + // initial check + this.checkAndLoad(); + }, + + /** + * Checks and loads the next page if required + */ + checkAndLoad: function() { + var recordLockedOrNotInPosition = this.lock || !this.checkPosition(); + var urlIsInvalid = typeof this.url === 'undefined' || this.url === this.lastUrl; + if (recordLockedOrNotInPosition || urlIsInvalid) { + return; + } + + this.lock = true; + $.ajax( + { + url: this.url, + + success: function(response) { + var results = $(response).find('.tx-sgnews-list'); + results.each(function(index, result) { + var $result = $(result); + var children = $result.children(); + if (!children.length) { + return; + } + + var $resultList = $('.tx-sgnews-list-' + $result.data('category')); + if (!$resultList.length) { + $resultList = $('.tx-sgnews-list'); + } + $resultList.append(children); + + this.loadIndicator = $resultList.children(':last'); + }); + + this.lastUrl = this.url; + this.url = $(response).find('.tx-pagebrowse-next a').attr('href'); + this.lock = false; + }.bind(this) + } ); }, -- GitLab