Skip to content

Commit 74a00c3

Browse files
committed
πŸ”” add fetchOptions option
πŸ›  line whitespace
1 parent e6813dc commit 74a00c3

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ let infScroll = new InfiniteScroll( '.container', {
8989
// enables parsing response body into a DOM
9090
// disable to load flat text
9191

92+
fetchOptions: undefined,
93+
// sets custom settings for the fetch() request
94+
// for setting headers, cors, or POST method
95+
// can be set to an object, or a function that returns an object
96+
9297
outlayer: false,
9398
// Integrates Masonry, Isotope or Packery
9499
// Appended items will be added to the layout

β€Žjs/core.jsβ€Ž

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ proto.log = function( type, args ) {
149149

150150
let message = `[InfiniteScroll] ${type}`;
151151
let logger = loggers[ type ];
152-
if ( logger ) {
153-
message += '. ' + logger.apply( this, args );
154-
}
152+
if ( logger ) message += '. ' + logger.apply( this, args );
155153
console.log( message );
156154
};
157155

β€Žjs/page-load.jsβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ let domParser = new DOMParser();
4747
proto.loadNextPage = function() {
4848
if ( this.isLoading || !this.canLoad ) return;
4949

50-
let { responseBody, domParseResponse } = this.options;
50+
let { responseBody, domParseResponse, fetchOptions } = this.options;
5151
let path = this.getAbsolutePath();
5252
this.isLoading = true;
53+
if ( typeof fetchOptions == 'function' ) fetchOptions = fetchOptions();
5354

5455
// TODO add fetch options
55-
let fetchPromise = fetch( path ).then( ( response ) => {
56+
let fetchPromise = fetch( path, fetchOptions ).then( ( response ) => {
5657
if ( !response.ok ) {
5758
let error = new Error( response.statusText );
5859
this.onPageError( error, path );

0 commit comments

Comments
Β (0)