fix some code style issues according to feedback

This commit is contained in:
Mike Greiling 2016-11-21 10:17:11 -06:00
parent ddab50b908
commit 0dd95ca983
2 changed files with 16 additions and 12 deletions

View file

@ -5,9 +5,9 @@
class Activities {
constructor() {
Pager.init(20, true, false, this.updateTooltips);
$('.event-filter-link').on('click', (event) => {
event.preventDefault();
this.toggleFilter($(event.currentTarget));
$('.event-filter-link').on('click', (e) => {
e.preventDefault();
this.toggleFilter(e.currentTarget);
this.reloadActivities();
});
}
@ -22,12 +22,13 @@
}
toggleFilter(sender) {
const filter = sender.attr('id').split('_')[0];
const $sender = $(sender);
const filter = $sender.attr('id').split('_')[0];
$('.event-filter .active').removeClass('active');
Cookies.set('event_filter', filter);
sender.closest('li').toggleClass('active');
$sender.closest('li').toggleClass('active');
}
}

View file

@ -1,15 +1,17 @@
(() => {
const ENDLESS_SCROLL_BOTTOM_PX = 400;
const ENDLESS_SCROLL_FIRE_DELAY_MS = 1000;
const Pager = {
init(limit = 0, preload = false, disable = false, callback = $.noop) {
this.limit = limit;
this.offset = this.limit;
this.disable = disable;
this.callback = callback;
this.loading = $('.loading').first();
if (preload) {
this.offset = 0;
this.getOld();
} else {
this.offset = this.limit;
}
this.initLoadMore();
},
@ -20,19 +22,19 @@
type: 'GET',
url: $('.content_list').data('href') || window.location.href,
data: `limit=${this.limit}&offset=${this.offset}`,
dataType: 'json',
error: () => this.loading.hide(),
success: (data) => {
this.append(data.count, data.html);
this.callback();
// keep loading until we've filled the viewport height
if (data.count > 0 && !this.isScrollable()) {
if (!this.disable && !this.isScrollable()) {
this.getOld();
} else {
this.loading.hide();
}
},
dataType: 'json',
});
},
@ -46,14 +48,15 @@
},
isScrollable() {
return $(document).height() > $(window).height() + $(window).scrollTop() + 400;
const $w = $(window);
return $(document).height() > $w.height() + $w.scrollTop() + ENDLESS_SCROLL_BOTTOM_PX;
},
initLoadMore() {
$(document).unbind('scroll');
$(document).endlessScroll({
bottomPixels: 400,
fireDelay: 1000,
bottomPixels: ENDLESS_SCROLL_BOTTOM_PX,
fireDelay: ENDLESS_SCROLL_FIRE_DELAY_MS,
fireOnce: true,
ceaseFire: () => this.disable === true,
callback: () => {