diff options
Diffstat (limited to 'app/assets/javascripts/pager.js')
-rw-r--r-- | app/assets/javascripts/pager.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/app/assets/javascripts/pager.js b/app/assets/javascripts/pager.js index f78d2b0dbd3..3ad9d80b4f2 100644 --- a/app/assets/javascripts/pager.js +++ b/app/assets/javascripts/pager.js @@ -8,20 +8,21 @@ const ENDLESS_SCROLL_BOTTOM_PX = 400; const ENDLESS_SCROLL_FIRE_DELAY_MS = 1000; export default { - init( + init({ limit = 0, preload = false, disable = false, prepareData = $.noop, - callback = $.noop, + successCallback = $.noop, + errorCallback = $.noop, container = '', - ) { - this.url = $('.content_list').data('href') || removeParams(['limit', 'offset']); + } = {}) { this.limit = limit; this.offset = parseInt(getParameterByName('offset'), 10) || this.limit; this.disable = disable; this.prepareData = prepareData; - this.callback = callback; + this.successCallback = successCallback; + this.errorCallback = errorCallback; this.loading = $(`${container} .loading`).first(); if (preload) { this.offset = 0; @@ -32,8 +33,10 @@ export default { getOld() { this.loading.show(); + const url = $('.content_list').data('href') || removeParams(['limit', 'offset']); + axios - .get(this.url, { + .get(url, { params: { limit: this.limit, offset: this.offset, @@ -41,7 +44,7 @@ export default { }) .then(({ data }) => { this.append(data.count, this.prepareData(data.html)); - this.callback(); + this.successCallback(); // keep loading until we've filled the viewport height if (!this.disable && !this.isScrollable()) { @@ -50,7 +53,8 @@ export default { this.loading.hide(); } }) - .catch(() => this.loading.hide()); + .catch((err) => this.errorCallback(err)) + .finally(() => this.loading.hide()); }, append(count, html) { |