Skip to content

Commit

Permalink
🐞 fix initializing with jQuery bridget
Browse files Browse the repository at this point in the history
add min.js
  • Loading branch information
desandro committed Jan 1, 2021
1 parent 222e655 commit 82910c6
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 5 deletions.
5 changes: 3 additions & 2 deletions dist/infinite-scroll.pkgd.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,9 @@ utils.htmlInit( InfiniteScroll, 'infinite-scroll' );
// add noop _init method for jQuery Bridget. #768
proto._init = function() {};

if ( jQuery && jQuery.bridget ) {
jQuery.bridget( 'infiniteScroll', InfiniteScroll );
let { jQueryBridget } = window;
if ( jQuery && jQueryBridget ) {
jQueryBridget( 'infiniteScroll', InfiniteScroll, jQuery );
}

// -------------------------- -------------------------- //
Expand Down
2 changes: 1 addition & 1 deletion dist/infinite-scroll.pkgd.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,9 @@ utils.htmlInit( InfiniteScroll, 'infinite-scroll' );
// add noop _init method for jQuery Bridget. #768
proto._init = function() {};

if ( jQuery && jQuery.bridget ) {
jQuery.bridget( 'infiniteScroll', InfiniteScroll );
let { jQueryBridget } = window;
if ( jQuery && jQueryBridget ) {
jQueryBridget( 'infiniteScroll', InfiniteScroll, jQuery );
}

// -------------------------- -------------------------- //
Expand Down
54 changes: 54 additions & 0 deletions test/dist-jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const test = require('ava');
const puppeteer = require('puppeteer');
const getServer = require('./_get-server.js');

const port = 9011;
let server, browser, page;

test.before( async function() {
server = getServer();
server.listen( port );
browser = await puppeteer.launch();
page = await browser.newPage();
await page.goto(`http://localhost:${port}/test/html/dist-jquery.html`);
} );

test.after( async function() {
page.close();
await browser.close();
server.close();
} );

// ------ tests ------ //

test( 'dist jQuery', async( t ) => {

let assertions = await page.evaluate( function() {
const { jQuery } = window;
let $container = document.querySelector('.container');
$container = jQuery('.container').infiniteScroll({
path: 'page/{{#}}.html',
append: '.post',
});

let infScroll = $container.data('infinite-scroll');

return $container.infiniteScroll('loadNextPage')
.then( function( load ) {
let { response, body, items } = load;
serialT.true( response instanceof Response );
serialT.true( response.ok );
serialT.is( response.status, 200 );
serialT.true( body instanceof HTMLDocument );
serialT.true( items instanceof NodeList );
serialT.is( items.length, 2 );
serialT.true( items[0] == $container[0].children[1] );
serialT.true( items[1] == $container[0].children[2] );
serialT.is( infScroll.pageIndex, 2 );
serialT.is( infScroll.loadCount, 1 );
} )
.then( () => serialT.assertions );
} );

assertions.forEach( ({ method, args }) => t[ method ]( ...args ) );
} );
28 changes: 28 additions & 0 deletions test/html/dist-jquery.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />

<title>Infinite Scroll test - dist jQuery</title>

<link rel="stylesheet" href="test.css" />

<!-- dependencies -->
<script src="../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../dist/infinite-scroll.pkgd.min.js"></script>
<!-- test helper -->
<script src="_serial-t.js"></script>

</head>
<body>

<h1>Infinite Scroll test - dist jQuery</h1>

<div class="container">
<div class="post">page 1, post 1</div>
</div>
<p><a class="next-link" href="page/2.html">Next</a></p>

</body>
</html>

0 comments on commit 82910c6

Please sign in to comment.