Commit 0dd95ca9 authored by Mike Greiling's avatar Mike Greiling

fix some code style issues according to feedback

parent ddab50b9
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
class Activities { class Activities {
constructor() { constructor() {
Pager.init(20, true, false, this.updateTooltips); Pager.init(20, true, false, this.updateTooltips);
$('.event-filter-link').on('click', (event) => { $('.event-filter-link').on('click', (e) => {
event.preventDefault(); e.preventDefault();
this.toggleFilter($(event.currentTarget)); this.toggleFilter(e.currentTarget);
this.reloadActivities(); this.reloadActivities();
}); });
} }
...@@ -22,12 +22,13 @@ ...@@ -22,12 +22,13 @@
} }
toggleFilter(sender) { toggleFilter(sender) {
const filter = sender.attr('id').split('_')[0]; const $sender = $(sender);
const filter = $sender.attr('id').split('_')[0];
$('.event-filter .active').removeClass('active'); $('.event-filter .active').removeClass('active');
Cookies.set('event_filter', filter); Cookies.set('event_filter', filter);
sender.closest('li').toggleClass('active'); $sender.closest('li').toggleClass('active');
} }
} }
......
(() => { (() => {
const ENDLESS_SCROLL_BOTTOM_PX = 400;
const ENDLESS_SCROLL_FIRE_DELAY_MS = 1000;
const Pager = { const Pager = {
init(limit = 0, preload = false, disable = false, callback = $.noop) { init(limit = 0, preload = false, disable = false, callback = $.noop) {
this.limit = limit; this.limit = limit;
this.offset = this.limit;
this.disable = disable; this.disable = disable;
this.callback = callback; this.callback = callback;
this.loading = $('.loading').first(); this.loading = $('.loading').first();
if (preload) { if (preload) {
this.offset = 0; this.offset = 0;
this.getOld(); this.getOld();
} else {
this.offset = this.limit;
} }
this.initLoadMore(); this.initLoadMore();
}, },
...@@ -20,19 +22,19 @@ ...@@ -20,19 +22,19 @@
type: 'GET', type: 'GET',
url: $('.content_list').data('href') || window.location.href, url: $('.content_list').data('href') || window.location.href,
data: `limit=${this.limit}&offset=${this.offset}`, data: `limit=${this.limit}&offset=${this.offset}`,
dataType: 'json',
error: () => this.loading.hide(), error: () => this.loading.hide(),
success: (data) => { success: (data) => {
this.append(data.count, data.html); this.append(data.count, data.html);
this.callback(); this.callback();
// keep loading until we've filled the viewport height // keep loading until we've filled the viewport height
if (data.count > 0 && !this.isScrollable()) { if (!this.disable && !this.isScrollable()) {
this.getOld(); this.getOld();
} else { } else {
this.loading.hide(); this.loading.hide();
} }
}, },
dataType: 'json',
}); });
}, },
...@@ -46,14 +48,15 @@ ...@@ -46,14 +48,15 @@
}, },
isScrollable() { isScrollable() {
return $(document).height() > $(window).height() + $(window).scrollTop() + 400; const $w = $(window);
return $(document).height() > $w.height() + $w.scrollTop() + ENDLESS_SCROLL_BOTTOM_PX;
}, },
initLoadMore() { initLoadMore() {
$(document).unbind('scroll'); $(document).unbind('scroll');
$(document).endlessScroll({ $(document).endlessScroll({
bottomPixels: 400, bottomPixels: ENDLESS_SCROLL_BOTTOM_PX,
fireDelay: 1000, fireDelay: ENDLESS_SCROLL_FIRE_DELAY_MS,
fireOnce: true, fireOnce: true,
ceaseFire: () => this.disable === true, ceaseFire: () => this.disable === true,
callback: () => { callback: () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment