Реализована автоподгрузка постов

parent 6198fc1d
......@@ -58,6 +58,7 @@ use common\modules\bids\models\Bid;
<?php ActiveForm::end(); ?>
</div>
<?php echo \common\modules\users\widgets\LoginWidget::widget(); ?>
<?php echo \common\modules\users\widgets\RegistrationWidget::widget(); ?>
<?php //todo ?? ?>
<?php //echo \common\modules\users\widgets\LoginWidget::widget(); ?>
<?php //echo \common\modules\users\widgets\RegistrationWidget::widget(); ?>
</div>
\ No newline at end of file
......@@ -68,41 +68,7 @@ $(document).ready(function() {
return false;
});
$('a#load-post').click(function() {
var button = $(this), loading = $('.loading-post'), offset = button.data('offset'), tag = button.data('tag');
button.hide();
loading.show();
$.ajax({
method: 'POST',
url: $(this).attr('href'),
data: {
offset: offset,
tag: tag
},
success: function(response)
{
$('.loaded').append(response.posts);
button.data('offset', response.offset);
if(response.count <= response.offset)
{
button.hide();
}
else
{
button.show();
}
loading.hide();
}
});
return false;
});
$('a#load-post').click(loadPosts);
$.ajax({
url: "/sessions/default/add"
......@@ -133,8 +99,57 @@ $(document).ready(function() {
}).on('submit', function(e){
return false;
});
var maxPosition = $(window).scrollTop();
$(window).scroll(function() {
var position = $(window).scrollTop() + $(window).height();
if(position >= maxPosition && position >= $(document).height() - 800 && !loadProcess && !allPostsLoaded) {
maxPosition = position;
loadPosts();
}
});
});
var loadProcess = false;
var allPostsLoaded = false;
function loadPosts() {
var button = $('a#load-post'), loading = $('.loading-post'), offset = button.data('offset'), tag = button.data('tag');
$.ajax({
method: 'POST',
url: button.attr('href'),
data: {
offset: offset,
tag: tag
},
success: function(response) {
$('.loaded').append(response.posts);
button.data('offset', response.offset);
if(response.count <= response.offset) {
allPostsLoaded = true;
button.hide();
}
else {
button.show();
}
},
beforeSend: function() {
button.hide();
loading.show();
loadProcess = true;
}
}).done(function() {
loading.hide();
loadProcess = false;
});
return false;
}
if($('#chart-container').length > 0)
{
FusionCharts.ready(function () {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment