AJAX pagination and some light house keeping

This commit is contained in:
Shea Dawson 2013-02-20 15:05:38 +11:00 committed by Will Rossiter
parent 3bdd155221
commit 4c5d7cd32b

View File

@ -4,11 +4,12 @@
(function($) { (function($) {
$(document).ready(function () { $(document).ready(function () {
var commentsHolder = $('.comments-holder'), var container = $('.comments-holder-container'),
commentsHolder = $('.comments-holder'),
commentsList = $('.comments-list', commentsHolder), commentsList = $('.comments-list', commentsHolder),
pagination = $('.comments-pagination'),
noCommentsYet = $('.no-comments-yet', commentsHolder), noCommentsYet = $('.no-comments-yet', commentsHolder),
form = $('#Form_CommentsForm'), form = $('form', container);
error = $('#Form_CommentsForm_error', form).hide()
/** /**
@ -104,7 +105,6 @@
$(".action-links a", commentsList).live('click', function(e) { $(".action-links a", commentsList).live('click', function(e) {
var link = $(this); var link = $(this);
var comment = link.parents('.comment:first'); var comment = link.parents('.comment:first');
var commentsList = comment.parents('ul:first');
$.ajax({ $.ajax({
url: $(this).attr('href'), url: $(this).attr('href'),
@ -130,17 +130,7 @@
}); });
} }
else if(link.hasClass('spam')) { else if(link.hasClass('spam')) {
if(html) {
comment.html(html).addClass('spam').hide().fadeIn(); comment.html(html).addClass('spam').hide().fadeIn();
} else {
comment.fadeOut(1000, function() { // Fade out the comment
comment.remove(); // remove the comment
if(comments.children().length == 0) {
noCommentsYet.show();
}
});
}
} }
}, },
failure: function(html) { failure: function(html) {
@ -149,6 +139,28 @@
}); });
e.preventDefault(); e.preventDefault();
}) });
/**
* Ajax pagination
*/
pagination.find('a').live('click', function(){
commentsList.addClass('loading');
$.ajax({
url: $(this).attr('href'),
cache: false,
success: function(html){
html = $(html);
commentsList.hide().html(html.find('.comments-list:first')).fadeIn();
pagination.hide().html(html.find('.comments-pagination:first')).fadeIn();
commentsList.removeClass('loading');
},
failure: function(html) {
alert('Error loading comments');
}
});
return false;
});
}); });
})(jQuery); })(jQuery);