Skip to content

Commit e421553

Browse files
author
fieg
committed
fix
1 parent 3eb308b commit e421553

File tree

2 files changed

+49
-12
lines changed

2 files changed

+49
-12
lines changed

src/jquery-ias.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,14 @@
499499

500500
// ready is already fired, before on() could even be called, so
501501
// let's call the callback right away
502-
if (event === 'ready' && this.isInitialized) {
503-
$.proxy(callback, this)();
504-
}
505-
// same applies to noneLeft
506-
else if (event === 'noneLeft' && !this.nextUrl) {
507-
$.proxy(callback, this)();
502+
if (this.isInitialized) {
503+
if (event === 'ready') {
504+
$.proxy(callback, this)();
505+
}
506+
// same applies to noneLeft
507+
else if (event === 'noneLeft' && !this.nextUrl) {
508+
$.proxy(callback, this)();
509+
}
508510
}
509511

510512
return this;

test/02-listeners-test.js

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ describe("IAS", function () {
171171
// register listener
172172
.on('noneLeft', spy1);
173173

174+
expect(spy1).not.toHaveBeenCalled();
175+
174176
// scroll to page 2
175177
scrollDown().then(function() {
176178
wait(2000).then(function() {
@@ -190,22 +192,55 @@ describe("IAS", function () {
190192
return deferred.promise;
191193
});
192194

193-
it("should call noneLeft listeners when content is short without next", function() {
195+
it("should call noneLeft listeners when content is short without next (before init)", function() {
194196
var deferred = when.defer();
195197
var spy1 = this.spy();
196198

197199
jQuery.ias('destroy');
198200

199201
loadFixture("short-without-next.html", function() {
200-
jQuery.ias({
202+
var ias = jQuery.ias({
201203
container : '.listing',
202204
item: '.post',
203205
pagination: '.navigation',
204206
next: '.next-posts a',
205-
initialize: true
206-
})
207-
// register listener
208-
.on('noneLeft', spy1);
207+
initialize: false
208+
});
209+
210+
// register listener
211+
ias.on('noneLeft', spy1);
212+
213+
expect(spy1).not.toHaveBeenCalled();
214+
215+
ias.initialize();
216+
217+
expect(spy1).toHaveBeenCalledOnce();
218+
219+
deferred.resolve();
220+
});
221+
222+
return deferred.promise;
223+
});
224+
225+
it("should call noneLeft listeners when content is short without next (after init)", function() {
226+
var deferred = when.defer();
227+
var spy1 = this.spy();
228+
229+
jQuery.ias('destroy');
230+
231+
loadFixture("short-without-next.html", function() {
232+
var ias = jQuery.ias({
233+
container : '.listing',
234+
item: '.post',
235+
pagination: '.navigation',
236+
next: '.next-posts a',
237+
initialize: false
238+
});
239+
240+
ias.initialize();
241+
242+
// register listener
243+
ias.on('noneLeft', spy1);
209244

210245
expect(spy1).toHaveBeenCalledOnce();
211246

0 commit comments

Comments
 (0)