2010-11-29 23:24:17 +01:00
|
|
|
/**
|
2013-02-19 07:46:58 +01:00
|
|
|
* @package comments
|
2010-11-29 23:24:17 +01:00
|
|
|
*/
|
2010-12-07 02:09:52 +01:00
|
|
|
(function($) {
|
|
|
|
$(document).ready(function () {
|
2013-02-20 05:05:38 +01:00
|
|
|
|
|
|
|
var container = $('.comments-holder-container'),
|
|
|
|
commentsHolder = $('.comments-holder'),
|
2013-02-19 07:46:58 +01:00
|
|
|
commentsList = $('.comments-list', commentsHolder),
|
2013-02-20 05:05:38 +01:00
|
|
|
pagination = $('.comments-pagination'),
|
2013-02-19 07:46:58 +01:00
|
|
|
noCommentsYet = $('.no-comments-yet', commentsHolder),
|
2013-03-04 11:37:18 +01:00
|
|
|
form = $('form', container),
|
|
|
|
previewEl = form.find('#PreviewComment');
|
2013-02-19 07:46:58 +01:00
|
|
|
|
2013-03-04 11:37:18 +01:00
|
|
|
/**
|
|
|
|
* Init
|
|
|
|
*/
|
|
|
|
previewEl.hide();
|
|
|
|
$(':submit[name=action_doPreviewComment]').show();
|
2013-02-19 07:46:58 +01:00
|
|
|
|
2010-12-11 06:01:19 +01:00
|
|
|
/**
|
2013-02-19 07:46:58 +01:00
|
|
|
* Validate
|
2010-12-11 06:01:19 +01:00
|
|
|
*/
|
2013-02-19 07:46:58 +01:00
|
|
|
form.validate({
|
2013-03-05 15:37:08 +01:00
|
|
|
invalidHandler : function(form, validator){
|
2013-02-19 07:46:58 +01:00
|
|
|
$('html, body').animate({
|
2013-03-05 15:37:08 +01:00
|
|
|
scrollTop: $(validator.errorList[0].element).offset().top - 30
|
|
|
|
}, 200);
|
2013-02-19 07:46:58 +01:00
|
|
|
},
|
2013-02-20 07:15:28 +01:00
|
|
|
showErrors: function(errorMap, errorList) {
|
2013-03-05 15:37:08 +01:00
|
|
|
this.defaultShowErrors();
|
|
|
|
// hack to add the extra classes we need to the validation message elements
|
|
|
|
form.find('span.error').addClass('message required');
|
|
|
|
},
|
2013-02-20 07:15:28 +01:00
|
|
|
|
2013-02-19 07:46:58 +01:00
|
|
|
errorElement: "span",
|
|
|
|
errorClass: "error",
|
2013-02-22 08:02:42 +01:00
|
|
|
ignore: '.hidden',
|
2013-02-19 07:46:58 +01:00
|
|
|
rules: {
|
|
|
|
Name : {
|
|
|
|
required : true
|
|
|
|
},
|
|
|
|
Email : {
|
|
|
|
required : true,
|
|
|
|
email : true
|
|
|
|
},
|
|
|
|
Comment: {
|
|
|
|
required : true
|
|
|
|
},
|
|
|
|
URL: {
|
|
|
|
url : true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
messages: {
|
|
|
|
Name : {
|
2013-02-20 07:15:28 +01:00
|
|
|
required : form.find('[name="Name"]').data('message-required')
|
2013-02-19 07:46:58 +01:00
|
|
|
},
|
|
|
|
Email : {
|
2013-02-20 07:15:28 +01:00
|
|
|
required : form.find('[name="Email"]').data('message-required'),
|
|
|
|
email : form.find('[name="Email"]').data('message-email')
|
2013-02-19 07:46:58 +01:00
|
|
|
},
|
|
|
|
Comment: {
|
2013-02-20 07:15:28 +01:00
|
|
|
required : form.find('[name="Comment"]').data('message-required')
|
2013-02-19 07:46:58 +01:00
|
|
|
},
|
|
|
|
URL: {
|
2013-02-20 07:15:28 +01:00
|
|
|
url : form.find('[name="Comment"]').data('message-url')
|
2013-02-19 07:46:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
form.submit(function (e) {
|
2013-02-20 07:15:28 +01:00
|
|
|
// trigger validation
|
2013-03-05 15:37:08 +01:00
|
|
|
if(!form.validate().valid()) return false;
|
2010-11-29 23:24:17 +01:00
|
|
|
});
|
2013-02-19 07:46:58 +01:00
|
|
|
|
2013-03-04 11:37:18 +01:00
|
|
|
/**
|
|
|
|
* Preview comment by fetching it from the server via ajax.
|
|
|
|
*/
|
|
|
|
$(':submit[name=action_doPreviewComment]', form).click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2013-03-05 10:01:42 +01:00
|
|
|
if(!form.validate().valid()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-04 11:37:18 +01:00
|
|
|
|
|
|
|
previewEl.show().addClass('loading').find('.middleColumn').html(' ');
|
2013-03-05 10:01:42 +01:00
|
|
|
|
2013-03-04 11:37:18 +01:00
|
|
|
form.ajaxSubmit({
|
|
|
|
success: function(response) {
|
|
|
|
var responseEl = $(response);
|
|
|
|
if(responseEl.is('form')) {
|
|
|
|
// Validation failed, renders form instead of single comment
|
2013-03-05 10:01:42 +01:00
|
|
|
form.find(".data-fields").replaceWith(responseEl.find(".data-fields"));
|
2013-03-04 11:37:18 +01:00
|
|
|
} else {
|
|
|
|
// Default behaviour
|
|
|
|
previewEl.removeClass('loading').find('.middleColumn').html(responseEl);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data: {'action_doPreviewComment': 1}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide outdated preview on form changes
|
|
|
|
*/
|
|
|
|
$(':input', form).on('change keydown', function() {
|
2013-03-05 10:01:42 +01:00
|
|
|
previewEl.removeClass('loading').hide();
|
2013-03-04 11:37:18 +01:00
|
|
|
});
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2010-12-07 02:09:52 +01:00
|
|
|
/**
|
|
|
|
* Clicking one of the metalinks performs the operation via ajax
|
|
|
|
* this inclues the spam and approve links
|
|
|
|
*/
|
2013-02-19 07:46:58 +01:00
|
|
|
$(".action-links a", commentsList).live('click', function(e) {
|
2010-12-07 02:09:52 +01:00
|
|
|
var link = $(this);
|
2013-02-19 07:46:58 +01:00
|
|
|
var comment = link.parents('.comment:first');
|
2010-12-07 02:09:52 +01:00
|
|
|
|
|
|
|
$.ajax({
|
2013-02-19 07:46:58 +01:00
|
|
|
url: $(this).attr('href'),
|
2010-12-07 02:09:52 +01:00
|
|
|
cache: false,
|
|
|
|
success: function(html){
|
|
|
|
if(link.hasClass('ham')) {
|
|
|
|
// comment has been marked as not spam
|
|
|
|
comment.html(html);
|
2013-02-19 07:46:58 +01:00
|
|
|
comment.removeClass('spam').hide().fadeIn();
|
2010-12-07 02:09:52 +01:00
|
|
|
}
|
|
|
|
else if(link.hasClass('approve')) {
|
|
|
|
// comment has been approved
|
|
|
|
comment.html(html);
|
2013-02-19 07:46:58 +01:00
|
|
|
comment.removeClass('unmoderated').hide().fadeIn();
|
2010-12-07 02:09:52 +01:00
|
|
|
}
|
|
|
|
else if(link.hasClass('delete')) {
|
2013-02-19 07:46:58 +01:00
|
|
|
comment.fadeOut(1000, function() {
|
|
|
|
comment.remove();
|
2010-12-07 02:09:52 +01:00
|
|
|
|
2013-02-19 07:46:58 +01:00
|
|
|
if(commentsList.children().length == 0) {
|
|
|
|
noCommentsYet.show();
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
2010-12-07 02:09:52 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else if(link.hasClass('spam')) {
|
2013-02-20 05:05:38 +01:00
|
|
|
comment.html(html).addClass('spam').hide().fadeIn();
|
2010-12-07 02:09:52 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
failure: function(html) {
|
|
|
|
alert(html)
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
2010-12-07 02:09:52 +01:00
|
|
|
});
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2010-12-07 02:09:52 +01:00
|
|
|
e.preventDefault();
|
2013-02-20 05:05:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajax pagination
|
|
|
|
*/
|
|
|
|
pagination.find('a').live('click', function(){
|
|
|
|
commentsList.addClass('loading');
|
|
|
|
$.ajax({
|
|
|
|
url: $(this).attr('href'),
|
|
|
|
cache: false,
|
|
|
|
success: function(html){
|
|
|
|
html = $(html);
|
2013-02-20 05:08:54 +01:00
|
|
|
commentsList.hide().html(html.find('.comments-list:first').html()).fadeIn();
|
|
|
|
pagination.hide().html(html.find('.comments-pagination:first').html()).fadeIn();
|
2013-02-20 05:05:38 +01:00
|
|
|
commentsList.removeClass('loading');
|
2013-02-20 07:24:05 +01:00
|
|
|
$('html, body').animate({
|
|
|
|
scrollTop: commentsList.offset().top - 30
|
|
|
|
}, 200);
|
2013-02-20 05:05:38 +01:00
|
|
|
},
|
|
|
|
failure: function(html) {
|
|
|
|
alert('Error loading comments');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
2010-12-07 02:09:52 +01:00
|
|
|
});
|
|
|
|
})(jQuery);
|