Skip to content

Commit 3eb308b

Browse files
author
fieg
committed
fire noneLeft on single page scenario
1 parent 181edf2 commit 3eb308b

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

src/jquery-ias.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,12 @@
388388

389389
this.nextUrl = this.getNextUrl();
390390

391+
if (!this.nextUrl) {
392+
this.fire('noneLeft', [this.getLastItem()]);
393+
}
394+
391395
// start loading next page if content is shorter than page fold
392-
if (currentScrollOffset >= scrollThreshold) {
396+
if (this.nextUrl && currentScrollOffset >= scrollThreshold) {
393397
this.next();
394398

395399
// flag as initialized when rendering is completed
@@ -498,6 +502,10 @@
498502
if (event === 'ready' && this.isInitialized) {
499503
$.proxy(callback, this)();
500504
}
505+
// same applies to noneLeft
506+
else if (event === 'noneLeft' && !this.nextUrl) {
507+
$.proxy(callback, this)();
508+
}
501509

502510
return this;
503511
};
@@ -567,7 +575,6 @@
567575

568576
if (!self.nextUrl) {
569577
self.fire('noneLeft', [self.getLastItem()]);
570-
self.listeners['noneLeft'].disable(); // disable it so it only fires once
571578
}
572579

573580
self.resume();

test/02-listeners-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,29 @@ describe("IAS", function () {
189189

190190
return deferred.promise;
191191
});
192+
193+
it("should call noneLeft listeners when content is short without next", function() {
194+
var deferred = when.defer();
195+
var spy1 = this.spy();
196+
197+
jQuery.ias('destroy');
198+
199+
loadFixture("short-without-next.html", function() {
200+
jQuery.ias({
201+
container : '.listing',
202+
item: '.post',
203+
pagination: '.navigation',
204+
next: '.next-posts a',
205+
initialize: true
206+
})
207+
// register listener
208+
.on('noneLeft', spy1);
209+
210+
expect(spy1).toHaveBeenCalledOnce();
211+
212+
deferred.resolve();
213+
});
214+
215+
return deferred.promise;
216+
});
192217
});

test/buster.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ config["My tests"] = {
3232
{ path: "/page3.html", file: "test/fixtures/page3.html" },
3333
{ path: "/framed.html", file: "test/fixtures/framed.html" },
3434
{ path: "/short.html", file: "test/fixtures/short.html" },
35+
{ path: "/short-without-next.html", file: "test/fixtures/short-without-next.html" },
3536
{ path: "/ajax1.html", file: "test/fixtures/ajax1.html" },
3637
{ path: "/ajax2.html", file: "test/fixtures/ajax2.html" },
3738
{ path: "/multiple1.html", file: "test/fixtures/multiple1.html" },
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+
<title>Very short Page 1</title>
6+
</head>
7+
<body>
8+
<div id="content">
9+
<div class="listing">
10+
<div class="post">
11+
<strong>item 1</strong>
12+
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
13+
</div>
14+
15+
<div class="post">
16+
<strong>item 2</strong>
17+
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
18+
</div>
19+
</div>
20+
21+
<div class="navigation">
22+
<ul>
23+
<li>1</li>
24+
</ul>
25+
</div>
26+
</div>
27+
28+
</body>
29+
</html>

0 commit comments

Comments
 (0)