<script type="text/javascript">
var busy = false;
var limit = 6
var offset = 0;
function displayRecords(lim, off) {
$.ajax({
type: "GET",
async: false,
url: "getrecords.php",
data: "limit=" + lim + "&offset=" + off,
cache: false,
beforeSend: function() {
$("#loader_message").html("").hide();
$('#loader_image').show();
},
success: function(html) {
$("#results").append(html);
$('#loader_image').hide();
if (html == "") {
$("#loader_message").html('<div class="progress"><div class="determinate red" style="width: 100%"></div></div><a href="../../" class="waves-effect waves-grey btn-flat m-b-xs grey lighten-2 center-align font" style="width: 100%">مطالب ثبت شده به پایان رسیده است،هرروز مطالب جدیدی به ثبت می رسد،می توانید هر روز سر بزنید</a>').show()
} else {
$("#loader_message").html('<div class="progress"><div class="indeterminate"></div></div>').show();
}
window.busy = false;
}
});
}
$(document).ready(function() {
// start to load the first set of data
if (busy == false) {
busy = true;
// start to load the first set of data
displayRecords(limit, offset);
}
$(window).scroll(function() {
// make sure u give the container id of the data to be loaded in.
if ($(window).scrollTop() + $(window).height() > $("#results").height() && !busy) {
busy = true;
offset = limit + offset;
// this is optional just to delay the loading of data
setTimeout(function() { displayRecords(limit, offset); }, 800);
// you can remove the above code and can use directly this function
// displayRecords(limit, offset);
var favorites = JSON.parse(localStorage.getItem('favorites')) || [];
favorites.forEach(function(favorite) {
document.getElementById(favorite).className = 'radius waves-effect fa fa-heart pointer favi';
});
document.querySelector('.list').addEventListener('click', function(e) {
var id = e.target.id,
item = e.target,
index = favorites.indexOf(id);
if (!id) return;
if (index == -1) {
favorites.push(id);
item.className = 'radius waves-effect fa fa-heart pointer favi';
} else {
favorites.splice(index, 1);
item.className = 'radius waves-effect fa fa-heart pointer fav ';
}
localStorage.setItem('favorites', JSON.stringify(favorites));
});
}
});
});
</script>