Skip to content

Commit

Permalink
Merge pull request sakaiproject#458 from juanjmerono/SAK-29308
Browse files Browse the repository at this point in the history
SAK-29308 Improve scroll detection to load more pages
  • Loading branch information
juanjmerono committed May 6, 2015
2 parents 52788fb + a14bc47 commit 6768e77
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions roster2/src/webapp/js/roster.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,18 @@
* Check if there is no scroll rendered and there are more pages
*/
roster.checkScroll = function () {
$(window).off('scroll.roster.rendered');
// Check if body height is lower than window height
// Check if body height is lower than window height (scrollbar missed, maybe you need to get more pages automatically)
if ($("body").height() <= $(window).height()) {
setTimeout(function () {
var renderedMembers = $(".roster-member").size();
if (roster.site.membersTotal > renderedMembers) {
// Without filter conditions get more pages if there are more members than rendered and rendered > 0
// If you have an active filter maybe you could display less members than total
// So get more pages only if rendered match a page size (10 is pagesize)
if (roster.site.membersTotal > renderedMembers && renderedMembers > 0 && renderedMembers % 10 === 0) {
$("body").data("scroll-roster", true);
$(window).on('scroll.roster.rendered', roster.checkScroll);
$(window).trigger('scroll.roster');
}
}, 500);
}, 100);
}
};

Expand All @@ -88,7 +89,7 @@

var t = Handlebars.templates[template];
document.getElementById(outputId).innerHTML = t(data);
$(window).trigger('scroll.roster.rendered');

};

roster.switchState = function (state, arg, searchQuery) {
Expand Down Expand Up @@ -527,9 +528,10 @@
};

var templateName = (enrollmentsMode) ? 'enrollments' : 'members';

$(window).off('scroll.roster.rendered').on('scroll.roster.rendered', roster.checkScroll);
var t = Handlebars.templates[templateName];
target.append(t(templateData));
$(window).trigger('scroll.roster.rendered');
};

roster.getScrollFunction = function (showOfficialPictures, enrollmentStatus) {
Expand Down Expand Up @@ -738,9 +740,4 @@
}
});

$(document).ready(function () {
// Ensure everything is rendered
setTimeout(function () { roster.checkScroll(); }, 500);
});

}) (jQuery);

0 comments on commit 6768e77

Please sign in to comment.