diff options
author | Mike Greiling <mike@pixelcog.com> | 2016-11-21 10:17:11 -0600 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2016-11-21 10:17:11 -0600 |
commit | 0dd95ca98381b4c6fc7016dd50dd3052051491b0 (patch) | |
tree | 0a4018c04d6a76aa539e85c4947cbc2e8df9098a /app | |
parent | ddab50b9082a74810631e138d7931a0ebf116751 (diff) | |
download | gitlab-ce-0dd95ca98381b4c6fc7016dd50dd3052051491b0.tar.gz |
fix some code style issues according to feedback24499-fix-activity-autoload-on-large-viewports
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/activities.js.es6 | 11 | ||||
-rw-r--r-- | app/assets/javascripts/pager.js.es6 | 17 |
2 files changed, 16 insertions, 12 deletions
diff --git a/app/assets/javascripts/activities.js.es6 b/app/assets/javascripts/activities.js.es6 index da8a4a8f3a2..19bcfef89fb 100644 --- a/app/assets/javascripts/activities.js.es6 +++ b/app/assets/javascripts/activities.js.es6 @@ -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'); } } diff --git a/app/assets/javascripts/pager.js.es6 b/app/assets/javascripts/pager.js.es6 index f0ae8950c5f..e35cf6d295e 100644 --- a/app/assets/javascripts/pager.js.es6 +++ b/app/assets/javascripts/pager.js.es6 @@ -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: () => { |