function infiniteScroll(){
var offset = 0;
// on initialise ajaxready à true au premier chargement de la fonction
$(window).data('ajaxready', true);
$('#content').append('
');
var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
$(window).scroll(function() {
// On teste si ajaxready vaut false, auquel cas on stoppe la fonction
if ($(window).data('ajaxready') == false) return;
if(($(window).scrollTop() + $(window).height() ) == $(document).height()
|| agentID && ($(window).scrollTop() + $(window).height()) + 150 > $(document).height()) {
// lorsqu'on commence un traitement, on met ajaxready à false
$(window).data('ajaxready', false);
$('#content #loader').fadeIn(400);
$.get('/more/' + offset + '/', function(data){
if (data != '') {
$('#content #loader').before(data);
$('#content .hidden').fadeIn(400);
offset+= 1;
// une fois tous les traitements effectués,
// on remet ajaxready à false
// afin de pouvoir rappeler la fonction
$(window).data('ajaxready', true);
}
$('#content #loader').fadeOut(400);
});
}
});
};
infiniteScroll();