Skip to content

Commit 68a7827

Browse files
author
fieg
committed
added initialize option
1 parent 93e36e8 commit 68a7827

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

doc/options.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,17 @@ For example:
8383
Setting a `negativeMargin` of 250 means that IAS will start loading 250 pixel before the last item has scrolled into view.
8484

8585
Note: user experience can degrade if new pages are loaded too quickly without visual feedback (also see [delay](options.html#delay)). Use with caution.
86+
87+
### initialize
88+
89+
<dl>
90+
<dt>Type</dt>
91+
<dd>boolean</dd>
92+
93+
<dt>Default</dt>
94+
<dd>true</dd>
95+
</dl>
96+
97+
By default IAS initializes when the document is ready. During initialisation IAS binds to the scroll event and prefills the container when the content is shorter then the page fold.
98+
99+
If you want to control when IAS initializes yourself, you can set this value to false.

src/jquery-ias.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,9 @@
627627
if (!instance) {
628628
$this.data('ias', (instance = new IAS($this, options)));
629629

630-
$(document).ready($.proxy(instance.initialize, instance));
630+
if (options.initialize) {
631+
$(document).ready($.proxy(instance.initialize, instance));
632+
}
631633
}
632634

633635
// when the plugin is called with a method
@@ -658,6 +660,7 @@
658660
next: '.next',
659661
pagination: false,
660662
delay: 600,
661-
negativeMargin: 10
663+
negativeMargin: 10,
664+
initialize: true
662665
};
663666
})(jQuery);

test/08-auto-initialize-test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
describe("IAS", function () {
2+
before(function() {
3+
this.timeout = 10000;
4+
5+
window.scrollTo(0, 0);
6+
});
7+
8+
after(function() {
9+
jQuery.ias('destroy');
10+
});
11+
12+
it("should initialize", function() {
13+
var deferred = when.defer();
14+
var spy = this.spy();
15+
16+
var ias = jQuery.ias({
17+
container : '.listing',
18+
item: '.post',
19+
pagination: '.navigation',
20+
next: '.next-posts a'
21+
});
22+
23+
ias.on('ready', spy);
24+
25+
wait(100).then(function() {
26+
expect(spy).toHaveBeenCalledOnce();
27+
28+
deferred.resolve();
29+
});
30+
31+
return deferred.promise;
32+
});
33+
34+
it("should not initialize", function() {
35+
var deferred = when.defer();
36+
var spy = this.spy();
37+
38+
var ias = jQuery.ias({
39+
container : '.listing',
40+
item: '.post',
41+
pagination: '.navigation',
42+
next: '.next-posts a',
43+
initialize: false
44+
});
45+
46+
ias.on('ready', spy);
47+
48+
wait(100).then(function() {
49+
expect(spy).not.toHaveBeenCalled();
50+
51+
deferred.resolve();
52+
});
53+
54+
return deferred.promise;
55+
});
56+
});

0 commit comments

Comments
 (0)