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($) {
|
2015-04-07 05:56:00 +02:00
|
|
|
$.entwine( "ss.comments", function($) {
|
2013-02-19 07:46:58 +01:00
|
|
|
|
2013-03-04 11:37:18 +01:00
|
|
|
/**
|
2015-04-07 05:56:00 +02:00
|
|
|
* Enable form validation
|
2013-03-04 11:37:18 +01:00
|
|
|
*/
|
2015-04-07 05:56:00 +02:00
|
|
|
$('.comments-holder-container form').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
|
|
|
|
// @todo Reinstate preview-comment functionality
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate
|
|
|
|
*/
|
|
|
|
$(this).validate({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ignore hidden elements in this form
|
|
|
|
*/
|
|
|
|
ignore: ':hidden',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use default 'required' for error labels
|
|
|
|
*/
|
|
|
|
errorClass: "required",
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use span instead of labels
|
|
|
|
*/
|
|
|
|
errorElement: "span",
|
2013-02-19 07:46:58 +01:00
|
|
|
|
2015-04-07 05:56:00 +02:00
|
|
|
/**
|
|
|
|
* On error, scroll to the invalid element
|
|
|
|
*/
|
|
|
|
invalidHandler : function(form, validator){
|
|
|
|
$('html, body').animate({
|
|
|
|
scrollTop: $(validator.errorList[0].element).offset().top - 30
|
|
|
|
}, 200);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure any new error message has the correct class and placement
|
|
|
|
*/
|
|
|
|
errorPlacement: function(error, element) {
|
|
|
|
error
|
|
|
|
.addClass('message')
|
|
|
|
.insertAfter(element);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-12-11 06:01:19 +01:00
|
|
|
/**
|
2015-04-07 05:56:00 +02:00
|
|
|
* Comment reply form
|
2010-12-11 06:01:19 +01:00
|
|
|
*/
|
2015-04-07 05:56:00 +02:00
|
|
|
$( ".comment-replies-container .comment-reply-form-holder" ).entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
// If and only if this is not the currently selected form, hide it on page load
|
|
|
|
var selectedHash = window.document.location.hash.substr(1),
|
|
|
|
form = $(this).children('.reply-form');
|
|
|
|
if( !selectedHash || selectedHash !== form.prop( 'id' ) ) {
|
|
|
|
this.hide();
|
2013-02-19 07:46:58 +01:00
|
|
|
}
|
2015-04-07 05:56:00 +02:00
|
|
|
this._super();
|
2013-02-19 07:46:58 +01:00
|
|
|
},
|
2015-04-07 05:56:00 +02:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
2013-02-19 07:46:58 +01:00
|
|
|
}
|
|
|
|
});
|
2015-04-07 05:56:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle on/off reply form
|
|
|
|
*/
|
|
|
|
$( ".comment-reply-link" ).entwine({
|
|
|
|
onclick: function( e ) {
|
|
|
|
var allForms = $( ".comment-reply-form-holder" ),
|
|
|
|
formID = $( this ).prop('href').replace(/^[^#]*#/, '#'),
|
|
|
|
form = $(formID).closest('.comment-reply-form-holder');
|
|
|
|
|
|
|
|
// Prevent focus
|
|
|
|
e.preventDefault();
|
|
|
|
if(form.is(':visible')) {
|
|
|
|
allForms.slideUp();
|
|
|
|
} else {
|
|
|
|
allForms.not(form).slideUp();
|
|
|
|
form.slideDown();
|
|
|
|
}
|
|
|
|
}
|
2010-11-29 23:24:17 +01:00
|
|
|
});
|
2015-04-07 05:56:00 +02: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.
|
|
|
|
*/
|
2015-04-07 05:56:00 +02:00
|
|
|
/* @todo Migrate to work with nested comments
|
2013-03-04 11:37:18 +01:00
|
|
|
$(':submit[name=action_doPreviewComment]', form).click(function(e) {
|
2015-04-07 05:56:00 +02:00
|
|
|
e.preventDefault();
|
2013-03-04 11:37:18 +01:00
|
|
|
|
2015-04-07 05:56:00 +02:00
|
|
|
if(!form.validate().valid()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-04 11:37:18 +01:00
|
|
|
|
2015-04-07 05:56:00 +02:00
|
|
|
previewEl.show().addClass('loading').find('.middleColumn').html(' ');
|
2013-03-05 10:01:42 +01:00
|
|
|
|
2015-04-07 05:56:00 +02:00
|
|
|
form.ajaxSubmit({
|
|
|
|
success: function(response) {
|
|
|
|
var responseEl = $(response);
|
|
|
|
if(responseEl.is('form')) {
|
|
|
|
// Validation failed, renders form instead of single comment
|
|
|
|
form.find(".data-fields").replaceWith(responseEl.find(".data-fields"));
|
|
|
|
} else {
|
|
|
|
// Default behaviour
|
|
|
|
previewEl.removeClass('loading').find('.middleColumn').html(responseEl);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data: {'action_doPreviewComment': 1}
|
|
|
|
});
|
2013-03-04 11:37:18 +01:00
|
|
|
});
|
2015-04-07 05:56:00 +02:00
|
|
|
*/
|
2013-03-04 11:37:18 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide outdated preview on form changes
|
|
|
|
*/
|
2015-04-07 05:56:00 +02:00
|
|
|
/*
|
2013-03-04 11:37:18 +01:00
|
|
|
$(':input', form).on('change keydown', function() {
|
2015-04-07 05:56:00 +02:00
|
|
|
previewEl.removeClass('loading').hide();
|
|
|
|
});*/
|
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
|
|
|
|
*/
|
2015-04-07 05:56:00 +02:00
|
|
|
/* @todo Migrate to work with nested comments
|
2014-07-02 18:51:08 +02:00
|
|
|
commentsList.on('click', '.action-links a', 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
|
|
|
});
|
2015-04-07 05:56:00 +02:00
|
|
|
*/
|
2013-02-20 05:05:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajax pagination
|
|
|
|
*/
|
2015-04-07 05:56:00 +02:00
|
|
|
/* @todo Migrate to work with nested comments
|
2014-04-07 04:35:42 +02:00
|
|
|
pagination.find('a').on('click', function(){
|
2013-02-20 05:05:38 +01:00
|
|
|
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({
|
2015-04-07 05:56:00 +02:00
|
|
|
scrollTop: commentsList.offset().top - 30
|
|
|
|
}, 200);
|
2013-02-20 05:05:38 +01:00
|
|
|
},
|
|
|
|
failure: function(html) {
|
|
|
|
alert('Error loading comments');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
2015-04-07 05:56:00 +02:00
|
|
|
});*/
|
2010-12-07 02:09:52 +01:00
|
|
|
});
|
|
|
|
})(jQuery);
|
2015-04-07 05:56:00 +02:00
|
|
|
|
|
|
|
|