Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.1.0 Upwards scroll support #809

Merged
merged 30 commits into from Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
35e2ef0
run npm install in examples as lock files are excluded from vcs
fieg Apr 11, 2022
e1e4d94
copied article as base for upwards scroll
fieg Apr 11, 2022
324bb5d
added prev default
fieg Apr 13, 2022
dc59d24
added events for upwards scroll
fieg Apr 13, 2022
755850c
prev and prepend handling
fieg Apr 13, 2022
795202b
keep track of last prev element
fieg Apr 15, 2022
d78f853
configure prev element
fieg Apr 15, 2022
72d3606
added top event
fieg Apr 15, 2022
e7313d1
added upwards scroll logic
fieg Apr 15, 2022
6aa8c75
prefill previous page
fieg Apr 15, 2022
d1d029a
use document.body
fieg Apr 18, 2022
8ff4df1
merged upwards example to articles example
fieg Aug 30, 2022
31ec302
disabled cache busting
fieg Aug 30, 2022
f9da60d
documented events and option
fieg Aug 30, 2022
1ff1d82
removed calledOnce check as other events are triggered as well
fieg Aug 30, 2022
78ab07f
return early when prev not configured
fieg Aug 30, 2022
76d3136
updated changelog
fieg Aug 30, 2022
d917981
updated readme to include prev option in example
fieg Aug 30, 2022
b7b7995
linked to issue in changelog
fieg Aug 30, 2022
4b3bded
Merge remote-tracking branch 'origin/master' into 3.1
fieg Aug 30, 2022
4b39bd8
bumped version to 3.1.0-beta.1
fieg Aug 30, 2022
916823d
Merge remote-tracking branch 'origin/master' into 3.1
fieg Sep 8, 2022
fafadea
pass along hasPrevUrl
fieg Sep 8, 2022
c99bd78
Merge remote-tracking branch 'origin/master' into 3.1
fieg Sep 8, 2022
d9056d1
Merge branch 'master' into 3.1
fieg Sep 21, 2022
ce84547
Merge remote-tracking branch 'origin/master' into 3.1
fieg Apr 9, 2023
1ef31f6
Preparation for 3.1.0 release
fieg Apr 9, 2023
1863efc
Merge remote-tracking branch 'origin/3.1' into 3.1
fieg Apr 9, 2023
207a356
removed merge conflict residue
fieg Apr 9, 2023
d19b00a
added descriptive text to 3.1.0 version in changelog
fieg Apr 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.1.0]

This version introduces upwards scroll support (fixes [#466](https://github.com/webcreate/infinite-ajax-scroll/issues/466)). See [`upwards scroll`](docs/advanced/upwards.md) documentation on how to use this feature.

* Adds all features from 3.1.0-beta.1
* Added [`upwards`](docs/advanced/upwards.md) documentation

## [3.1.0-beta.1]

This version introduces upwards scroll support (fixes [#466](https://github.com/webcreate/infinite-ajax-scroll/issues/466)). See documentation on the [`prev`](docs/options.md#prev) option on how to enable this feature.

* Added [`prev`](docs/options.md#prev) option
* Added [`prev`](docs/events.md#prev) event
* Added [`preved`](docs/events.md#preved) event
* Added [`top`](docs/events.md#top) event
* Added [`first`](docs/events.md#first) event
* Added [`prepend`](docs/events.md#prepend) event
* Added [`prepended`](docs/events.md#prepended) event

## [3.0.1]

* Fixed prefill not filling past the scroll threshold
Expand Down Expand Up @@ -111,6 +130,8 @@ See [LICENSE](LICENSE) for more details.
* Extensible through events
* Added an extensive test suite

[3.1.0]: https://github.com/webcreate/infinite-ajax-scroll/compare/3.0.1...3.1.0
[3.1.0-beta.1]: https://github.com/webcreate/infinite-ajax-scroll/compare/3.0.1...3.1.0-beta.1
[3.0.1]: https://github.com/webcreate/infinite-ajax-scroll/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/webcreate/infinite-ajax-scroll/compare/3.0.0-rc.1...3.0.0
[3.0.0-rc.1]: https://github.com/webcreate/infinite-ajax-scroll/compare/v2.3.1...3.0.0-rc.1
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -13,7 +13,7 @@ install:
update:
npm ci
npm run build
$(foreach ex,$(EXAMPLES),(cd $(ex) && npm ci) || exit $$?;)
$(foreach ex,$(EXAMPLES),(cd $(ex) && npm install) || exit $$?;)
.PHONY: update

up:
Expand Down
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -49,7 +49,9 @@ Infinite Ajax Scroll works on a container with item elements which get appended.
</div>

<div class="pagination">
<a href="page2.html" class="next">Next</a>
<a href="page1.html" class="prev">Prev</a>
<span class="current">2</span>
<a href="page3.html" class="next">Next</a>
</div>
```

Expand All @@ -62,6 +64,7 @@ import InfiniteAjaxScroll from '@webcreate/infinite-ajax-scroll';
let ias = new InfiniteAjaxScroll('.container', {
item: '.item',
next: '.next',
prev: '.prev',
pagination: '.pagination'
});
```
Expand Down
5 changes: 5 additions & 0 deletions UPGRADE.md
@@ -1,3 +1,8 @@
Upgrade from 3.0.x to 3.1.0
===========================

Version 3.1.0 is backwards-compatible with 3.0.x.

Upgrade from 2.3.x to 3.0
=========================

Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Expand Up @@ -18,3 +18,4 @@
* [Last page message](advanced/last-page-message.md)
* [History](advanced/history.md)
* [Overflow](advanced/overflow.md)
* [Upward scroll](advanced/upwards.md)
7 changes: 4 additions & 3 deletions docs/advanced/history.md
Expand Up @@ -23,6 +23,7 @@ ias.on('page', (event) => {

## Loading previous pages

{% hint style='working' %}
This feature is still work in progress
{% endhint %}
Infinite Ajax Scroll can also be used to load items above the current scroll position. This is useful when you want to load older items first.

[View upwards infinite scroll documentation](upwards.md)

61 changes: 61 additions & 0 deletions docs/advanced/upwards.md
@@ -0,0 +1,61 @@
# Upward Infinite Scroll

Infinite Ajax Scroll can also be used to load items above the current scroll position. This is useful when you want to load older items first.

*Introduced in Infinite Ajax Scroll 3.1.0*

## Caveats

### Fixed height images

Upward scroll works by calculation screen height and content height. Due to they way browser load content, especially images, this could cause incorrect measurements. This can be solved by using fixed height images.

## Setup

1. Add a previous page link to your pagination.

```html
<div class="pagination">
<a href="page1.html" class="prev">Prev</a>
<span class="current">2</span>
<a href="page3.html" class="next">Next</a>
</div>
```

2. Configure the [`prev`](../options.md#prev) option.

```javascript
// import if you use the NPM package
import InfiniteAjaxScroll from '@webcreate/infinite-ajax-scroll';

let ias = new InfiniteAjaxScroll('.container', {
item: '.item',
next: '.next',
prev: '.prev',
pagination: '.pagination'
});
```

## Hook into upward scroll with events

In this example we notify the user about loading the previous page.

```js
ias.on('prev', function(event) {
// pageIndex is 0-indexed, so we add 1
alert(`Page ${event.pageIndex+1} is loading...`);
});
ias.on('preved', function(event) {
alert(`Page ${event.pageIndex+1} is loaded and prepended to the page.`);
});
```

## Inform user about first page reached

In this example we notify the user when the first page is reached.

```javascript
ias.on('first', () => {
console.log('User has reached the first page');
})
```
83 changes: 82 additions & 1 deletion docs/events.md
Expand Up @@ -63,6 +63,16 @@ Triggered when the user has hit the scroll threshold for the next page due to sc
| :--- | :--- | :--- |
| distance | int | The distance to the scroll threshold in pixels |

### top

*Introduced in Infinite Ajax Scroll 3.1.0*

Triggered when the user has hit the top of the scroll area for the previous page due to scrolling or resizing.

| property | type | description |
| :--- | :--- |:---------------------------------------|
| distance | int | The distance to the scroll top in pixels |

### next

Triggered right after the `hit` event. Indicating that the next page will be loaded.
Expand Down Expand Up @@ -93,6 +103,40 @@ Trigger when loading and appending the next page is completed.
| :--- | :--- | :--- |
| pageIndex | int | The page index of the next page (the page that is finished loading) |

### prev

*Introduced in Infinite Ajax Scroll 3.1.0*

Triggered right after the `top` event. Indicating that the previous page will be loaded.

| property | type | description |
| :--- | :--- |:----------------------------------------------------------------------|
| pageIndex | int | The page index of the prev page (the page that is about to be loaded) |

> pageIndex is zero indexed. This means the index starts at 0 on the first page.

For example to notify the user about loading the previous page, you can do:

```js
ias.on('prev', function(event) {
// pageIndex is 0-indexed, so we add 1
alert(`Page ${event.pageIndex+1} is loading...`);
});
ias.on('preved', function(event) {
alert(`Page ${event.pageIndex+1} is loaded and prepended to the page.`);
});
```

### preved

*Introduced in Infinite Ajax Scroll 3.1.0*

Trigger when loading and prepending the previous page is completed.

| property | type | description |
| :--- | :--- | :--- |
| pageIndex | int | The page index of the next page (the page that is finished loading) |

### load

This event is triggered before the next page is requested from the server.
Expand Down Expand Up @@ -158,18 +202,55 @@ This event is triggered after the items have been appended.
| items | array | Array of items that have been appended |
| parent | Element | The element to which the items have been appended |

### prepend

*Introduced in Infinite Ajax Scroll 3.1.0*

This event is triggered before the items are about to be prepended.

| property | type | description |
| :--- | :--- |:-------------------------------------------------|
| items | array | Array of items that will be prepended |
| parent | Element | The element to which the items will be prepended |
| prependFn | function | Function used to prepend items to the container |

See [src/prepend.js](../src/prepend.js) for the default prepend function.

### prepended

*Introduced in Infinite Ajax Scroll 3.1.0*

This event is triggered after the items have been prepended.

| property | type | description |
| :--- | :--- |:---------------------------------------------------|
| items | array | Array of items that have been prepended |
| parent | Element | The element to which the items have been prepended |

### last

Triggered when the last page is appended.

```javascript
ias.on('last', () => {
console.log('Users has reached the last page');
console.log('User has reached the last page');
})
```

[Read more on how we can inform the user about reaching the last page](advanced/last-page-message.md)

### first

*Introduced in Infinite Ajax Scroll 3.1.0*

Triggered when the last page is appended.

```javascript
ias.on('first', () => {
console.log('User has reached the first page');
})
```

### page

Triggered when the user scrolls past a page break. The event provides information about the page in view.
Expand Down
23 changes: 23 additions & 0 deletions docs/options.md
Expand Up @@ -44,6 +44,29 @@ let ias = new InfiniteAjaxScroll(/*..*/, {
})
```

## prev

*Introduced in Infinite Ajax Scroll 3.1.0*

**Type:** `string`<br>
**Default:** `undefined`<br>
**Required:** no

Selector of the previous link. The `href` attribute will be used for the url of the previous page. Only a single element should match this selector.

```html
<a href="/page/1" class="pager__prev">Prev</a>
<span class="pager__current">2</span>
<a href="/page/3" class="pager__next">Next</a>
```

```javascript
let ias = new InfiniteAjaxScroll(/*..*/, {
next: '.pager__next',
prev: '.pager__prev'
})
```

## pagination

**Type:** `boolean|string|Element`<br>
Expand Down
6 changes: 6 additions & 0 deletions examples/articles/index.js
Expand Up @@ -3,6 +3,7 @@ import InfiniteAjaxScroll from '@webcreate/infinite-ajax-scroll';
window.ias = new InfiniteAjaxScroll('.surface-container', {
item: '.article',
next: '.pager__next',
prev: '.pager__prev',
pagination: '.pager',
spinner: '.loader'
});
Expand All @@ -21,3 +22,8 @@ ias.on('page', (e) => {

history.replaceState(state, e.title, e.url);
});

// disable cache busting
ias.on('load', function(event) {
event.nocache = true;
});
2 changes: 1 addition & 1 deletion examples/articles/package.json
Expand Up @@ -29,7 +29,7 @@
"jquery-ias"
],
"dependencies": {
"@webcreate/infinite-ajax-scroll": "^3.0.0"
"@webcreate/infinite-ajax-scroll": "^3.1.0"
},
"devDependencies": {
"parcel": "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@webcreate/infinite-ajax-scroll",
"version": "3.0.1",
"version": "3.1.0",
"title": "Infinite Ajax Scroll",
"description": "Turn your existing pagination into infinite scrolling pages with ease",
"license": "AGPL-3.0-only",
Expand Down
1 change: 1 addition & 0 deletions src/defaults.js
@@ -1,6 +1,7 @@
export default {
item: undefined,
next: undefined,
prev: undefined,
pagination: undefined,
responseType: 'document',
bind: true,
Expand Down
12 changes: 12 additions & 0 deletions src/events.js
@@ -1,14 +1,20 @@
export const APPEND = 'append';
export const APPENDED = 'appended';
export const PREPEND = 'prepend';
export const PREPENDED = 'prepended';
export const BINDED = 'binded';
export const UNBINDED = 'unbinded';
export const HIT = 'hit';
export const TOP = 'top';
export const LOAD = 'load';
export const LOADED = 'loaded';
export const ERROR = 'error';
export const FIRST = 'first';
export const LAST = 'last';
export const NEXT = 'next';
export const NEXTED = 'nexted';
export const PREV = 'prev';
export const PREVED = 'preved';
export const READY = 'ready';
export const SCROLLED = 'scrolled';
export const RESIZED = 'resized';
Expand All @@ -19,15 +25,21 @@ export const PREFILLED = 'prefilled';
const events = {
APPEND,
APPENDED,
PREPEND,
PREPENDED,
BINDED,
UNBINDED,
HIT,
TOP,
LOAD,
LOADED,
ERROR,
FIRST,
LAST,
NEXT,
NEXTED,
PREV,
PREVED,
READY,
SCROLLED,
RESIZED,
Expand Down