artoo.js’ autoExpand methods let you expand web pages’ contents programmatically.
This is useful in pages that require user input like clicking on buttons triggering ajax requests or in pages featuring an infinite scroll.
Programmatically expand page’s content by performing some action and waiting for their results.
artoo.autoExpand(params, [callback]);
Concept
You can basically expand content on webpage by following two distincts approaches:
autoExpand method and it will react based on this.Examples
// Approach n°1
// We track the number of posts elements and we
// expand the content by clicking the relevant button.
artoo.autoExpand({
elements: '.posts',
expand: '.expand-button',
limit: 2,
done: function() {
console.log('Done expanding posts twice!');
}
});
// Approach n°2
// Here, if the expand button exist, we click it
// and we wait until the loading gif has disappeared
// to continue our expansion.
artoo.autoExpand({
expand: function($) {
$('.expand-button').simulate('click');
},
canExpand: '.expand-button',
isExpanding: function($) {
return $('.post-loading-gif').is(':visible');
},
throttle: 5000,
done: function() {
console.log('Done expanding every posts!');
}
});
Arguments
.posts, the autoExpand method will wait until more of those elements exist to assert the expansion has worked.callback argument.The autoScroll method is an autoExpand variant that does not take an expand function as it assumes this one has only to scroll the page to its bottom.
You remain free to pass any parameters to the autoScroll method the same way you would with the autoExpand one.
artoo.autoScroll([params, callback]);
Example
artoo.autoScroll({
elements: '.posts',
limit: 3,
done: function() {
console.log('Finished scrolling three times!');
}
});