Skip to content

Commit f9da60d

Browse files
committed
documented events and option
1 parent 31ec302 commit f9da60d

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

docs/events.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ Triggered when the user has hit the scroll threshold for the next page due to sc
6363
| :--- | :--- | :--- |
6464
| distance | int | The distance to the scroll threshold in pixels |
6565

66+
### top
67+
68+
Triggered when the user has hit the top of the scroll area for the previous page due to scrolling or resizing.
69+
70+
| property | type | description |
71+
| :--- | :--- |:---------------------------------------|
72+
| distance | int | The distance to the scroll top in pixels |
73+
6674
### next
6775

6876
Triggered right after the `hit` event. Indicating that the next page will be loaded.
@@ -93,6 +101,36 @@ Trigger when loading and appending the next page is completed.
93101
| :--- | :--- | :--- |
94102
| pageIndex | int | The page index of the next page (the page that is finished loading) |
95103

104+
### prev
105+
106+
Triggered right after the `top` event. Indicating that the previous page will be loaded.
107+
108+
| property | type | description |
109+
| :--- | :--- | :--- |
110+
| pageIndex | int | The page index of the next page (the page that is about to be loaded) |
111+
112+
> pageIndex is zero indexed. This means the index starts at 0 on the first page.
113+
114+
For example to notify the user about loading the next page, you can do:
115+
116+
```js
117+
ias.on('prev', function(event) {
118+
// pageIndex is 0-indexed, so we add 1
119+
alert(`Page ${event.pageIndex+1} is loading...`);
120+
});
121+
ias.on('preved', function(event) {
122+
alert(`Page ${event.pageIndex+1} is loaded and prepended to the page.`);
123+
});
124+
```
125+
126+
### preved
127+
128+
Trigger when loading and prepending the previous page is completed.
129+
130+
| property | type | description |
131+
| :--- | :--- | :--- |
132+
| pageIndex | int | The page index of the next page (the page that is finished loading) |
133+
96134
### load
97135

98136
This event is triggered before the next page is requested from the server.
@@ -158,18 +196,49 @@ This event is triggered after the items have been appended.
158196
| items | array | Array of items that have been appended |
159197
| parent | Element | The element to which the items have been appended |
160198

199+
### prepend
200+
201+
This event is triggered before the items are about to be prepended.
202+
203+
| property | type | description |
204+
| :--- | :--- |:-------------------------------------------------|
205+
| items | array | Array of items that will be prepended |
206+
| parent | Element | The element to which the items will be prepended |
207+
| prependFn | function | Function used to append items to the container |
208+
209+
See [src/append.js](../src/append.js) for the default append function.
210+
211+
### prepended
212+
213+
This event is triggered after the items have been prepended.
214+
215+
| property | type | description |
216+
| :--- | :--- |:---------------------------------------------------|
217+
| items | array | Array of items that have been prepended |
218+
| parent | Element | The element to which the items have been prepended |
219+
161220
### last
162221

163222
Triggered when the last page is appended.
164223

165224
```javascript
166225
ias.on('last', () => {
167-
console.log('Users has reached the last page');
226+
console.log('User has reached the last page');
168227
})
169228
```
170229

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

232+
### first
233+
234+
Triggered when the last page is appended.
235+
236+
```javascript
237+
ias.on('first', () => {
238+
console.log('User has reached the first page');
239+
})
240+
```
241+
173242
### page
174243

175244
Triggered when the user scrolls past a page break. The event provides information about the page in view.

docs/options.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ let ias = new InfiniteAjaxScroll(/*..*/, {
4444
})
4545
```
4646

47+
## prev
48+
49+
**Type:** `string`<br>
50+
**Default:** `undefined`<br>
51+
**Required:** no
52+
53+
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.
54+
55+
```html
56+
<a href="/page/1" class="pager__prev">Prev</a>
57+
```
58+
59+
```javascript
60+
let ias = new InfiniteAjaxScroll(/*..*/, {
61+
prev: '.pager__prev'
62+
})
63+
```
64+
4765
## pagination
4866

4967
**Type:** `boolean|string|Element`<br>

0 commit comments

Comments
 (0)