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($) {
|
2019-01-11 02:37:24 +01:00
|
|
|
// The above closure encapsulates the $ variable away from the global scope
|
|
|
|
// and the one below is the `$(document).ready(...)` shorthand.
|
2018-04-26 07:42:08 +02:00
|
|
|
$(function() {
|
2019-01-11 02:37:24 +01:00
|
|
|
// Override the default URL validator in order to extend it to allow protocol-less URLs
|
|
|
|
$.validator.methods.url = function( value, element ) {
|
|
|
|
// This line is copied directly from the jQuery.validation source (version 1.19.0)
|
|
|
|
// the only change is a single question mark added here ---------v
|
|
|
|
return this.optional( element ) || /^(?:(?:(?:https?|ftp):)?\/\/)?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test( value );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2018-06-25 01:31:46 +02:00
|
|
|
$('.comments-holder-container form').each(function() {
|
|
|
|
$(this).validate({
|
2015-04-07 05:56:00 +02:00
|
|
|
|
2018-06-25 01:31:46 +02:00
|
|
|
// Ignore hidden elements in this form
|
|
|
|
ignore: ':hidden',
|
2015-04-07 05:56:00 +02:00
|
|
|
|
2018-06-25 01:31:46 +02:00
|
|
|
// Use default 'required' for error labels
|
|
|
|
errorClass: "required",
|
2015-04-07 05:56:00 +02:00
|
|
|
|
2018-06-25 01:31:46 +02:00
|
|
|
// Use span instead of labels
|
|
|
|
errorElement: "span",
|
2013-02-19 07:46:58 +01:00
|
|
|
|
2018-06-25 01:31:46 +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);
|
|
|
|
},
|
2016-02-10 05:56:14 +01:00
|
|
|
|
2018-06-25 01:31:46 +02:00
|
|
|
// Ensure any new error message has the correct class and placement
|
|
|
|
errorPlacement: function(error, element) {
|
|
|
|
error
|
|
|
|
.addClass('message')
|
|
|
|
.insertAfter(element);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2016-02-10 05:56:14 +01:00
|
|
|
|
2015-04-07 05:56:00 +02:00
|
|
|
/**
|
2018-04-26 07:42:08 +02:00
|
|
|
* Hide comment reply forms by default (unless visiting via permalink)
|
2015-04-07 05:56:00 +02:00
|
|
|
*/
|
2018-04-26 07:42:08 +02:00
|
|
|
$(".comment")
|
|
|
|
.children('.info')
|
|
|
|
.not(window.document.location.hash)
|
|
|
|
.nextAll(".comment-replies-container")
|
|
|
|
.children(".comment-reply-form-holder")
|
|
|
|
.hide();
|
2013-02-19 07:46:58 +01:00
|
|
|
|
2013-03-04 11:37:18 +01:00
|
|
|
/**
|
2018-04-26 07:42:08 +02:00
|
|
|
* Toggle on/off reply form
|
2013-03-04 11:37:18 +01:00
|
|
|
*/
|
2018-04-26 07:42:08 +02:00
|
|
|
$('.comments-holder').on('click', '.comment-reply-link', function(e) {
|
|
|
|
var allForms = $('.comment-reply-form-holder');
|
|
|
|
var formID = '#' + $(this).attr('aria-controls');
|
|
|
|
var form = $(formID).closest('.comment-reply-form-holder');
|
2013-03-04 11:37:18 +01:00
|
|
|
|
2018-04-26 07:42:08 +02:00
|
|
|
$(this).attr('aria-expanded', function (i, attr) {
|
|
|
|
return attr == 'true' ? 'false' : 'true'
|
|
|
|
});
|
2013-03-05 10:01:42 +01:00
|
|
|
|
2018-04-26 07:42:08 +02:00
|
|
|
// Prevent focus
|
|
|
|
e.preventDefault();
|
2018-06-25 01:31:46 +02:00
|
|
|
|
2018-04-26 07:42:08 +02:00
|
|
|
if(form.is(':visible')) {
|
|
|
|
allForms.slideUp();
|
|
|
|
} else {
|
|
|
|
allForms.not(form).slideUp();
|
|
|
|
form.slideDown();
|
|
|
|
}
|
2013-03-04 11:37:18 +01:00
|
|
|
});
|
2016-02-10 05:56:14 +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
|
|
|
|
*/
|
2016-02-10 05:56:14 +01:00
|
|
|
$('.comments-holder .comments-list').on('click', 'div.comment-moderation-options a', function(e) {
|
2018-04-26 07:42:08 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
|
2010-12-07 02:09:52 +01:00
|
|
|
var link = $(this);
|
2018-04-26 07:42:08 +02:00
|
|
|
if (link.hasClass('delete')) {
|
|
|
|
var confirmationMsg = ss.i18n._t('CommentsInterface_singlecomment_ss.DELETE_CONFIRMATION');
|
|
|
|
var confirmation = window.confirm(confirmationMsg);
|
|
|
|
if (!confirmation) {
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-02-19 07:46:58 +01:00
|
|
|
var comment = link.parents('.comment:first');
|
2016-02-10 05:56:14 +01:00
|
|
|
|
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);
|
2016-02-10 05:56:14 +01:00
|
|
|
comment.removeClass('spam');
|
2010-12-07 02:09:52 +01:00
|
|
|
}
|
|
|
|
else if(link.hasClass('approve')) {
|
|
|
|
// comment has been approved
|
|
|
|
comment.html(html);
|
2016-02-10 05:56:14 +01:00
|
|
|
comment.removeClass('unmoderated');
|
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() {
|
2018-04-26 07:42:08 +02:00
|
|
|
comment.remove();
|
2016-02-10 05:56:14 +01:00
|
|
|
|
2018-04-26 07:42:08 +02:00
|
|
|
if($('.comments-holder .comments-list').children().length === 0) {
|
|
|
|
$('.no-comments-yet').show();
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
2010-12-07 02:09:52 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else if(link.hasClass('spam')) {
|
2016-02-10 05:56:14 +01:00
|
|
|
comment.html(html).addClass('spam');
|
2010-12-07 02:09:52 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
failure: function(html) {
|
2016-02-10 05:56:14 +01:00
|
|
|
var errorMsg = ss.i18n._t('CommentsInterface_singlecomment_ss.AJAX_ERROR');
|
2018-04-26 07:42:08 +02:00
|
|
|
alert(errorMsg);
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
2010-12-07 02:09:52 +01:00
|
|
|
});
|
2016-02-10 05:56:14 +01:00
|
|
|
|
2010-12-07 02:09:52 +01:00
|
|
|
e.preventDefault();
|
2013-02-20 05:05:38 +01:00
|
|
|
});
|
2010-12-07 02:09:52 +01:00
|
|
|
});
|
|
|
|
})(jQuery);
|