FIX Resolve linting issues

This commit is contained in:
Guy Sartorelli 2023-01-19 17:46:38 +13:00
parent 81902f6293
commit 0048a7abb9
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A

View File

@ -1,41 +1,42 @@
/* global ss, jQuery */
/** /**
* @package comments * @package comments
*/ */
(function ($) { (function ($) {
// The above closure encapsulates the $ variable away from the global scope // The above closure encapsulates the $ variable away from the global scope
// and the one below is the `$(document).ready(...)` shorthand. // and the one below is the `$(document).ready(...)` shorthand.
$(function() { $(() => {
// Override the default URL validator in order to extend it to allow protocol-less URLs // Override the default URL validator in order to extend it to allow protocol-less URLs
$.validator.methods.url = function (value, element) { $.validator.methods.url = function (value, element) {
// This line is copied directly from the jQuery.validation source (version 1.19.0) // 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 // the only change is a single question mark added here -------v
// eslint-disable-next-line max-len
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); 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);
} };
/** /**
* Enable form validation * Enable form validation
*/ */
$('.comments-holder-container form').each(function () { $('.comments-holder-container form').each(function () {
$(this).validate({ $(this).validate({
// Ignore hidden elements in this form // Ignore hidden elements in this form
ignore: ':hidden', ignore: ':hidden',
// Use default 'required' for error labels // Use default 'required' for error labels
errorClass: "required", errorClass: 'required',
// Use span instead of labels // Use span instead of labels
errorElement: "span", errorElement: 'span',
// On error, scroll to the invalid element // On error, scroll to the invalid element
invalidHandler : function(form, validator){ invalidHandler(form, validator) {
$('html, body').animate({ $('html, body').animate({
scrollTop: $(validator.errorList[0].element).offset().top - 30 scrollTop: $(validator.errorList[0].element).offset().top - 30
}, 200); }, 200);
}, },
// Ensure any new error message has the correct class and placement // Ensure any new error message has the correct class and placement
errorPlacement: function(error, element) { errorPlacement(error, element) {
error error
.addClass('message') .addClass('message')
.insertAfter(element); .insertAfter(element);
@ -46,24 +47,22 @@
/** /**
* Hide comment reply forms by default (unless visiting via permalink) * Hide comment reply forms by default (unless visiting via permalink)
*/ */
$(".comment") $('.comment')
.children('.info') .children('.info')
.not(window.document.location.hash) .not(window.document.location.hash)
.nextAll(".comment-replies-container") .nextAll('.comment-replies-container')
.children(".comment-reply-form-holder") .children('.comment-reply-form-holder')
.hide(); .hide();
/** /**
* Toggle on/off reply form * Toggle on/off reply form
*/ */
$('.comments-holder').on('click', '.comment-reply-link', function (e) { $('.comments-holder').on('click', '.comment-reply-link', function (e) {
var allForms = $('.comment-reply-form-holder'); const allForms = $('.comment-reply-form-holder');
var formID = '#' + $(this).attr('aria-controls'); const formID = `#${$(this).attr('aria-controls')}`;
var form = $(formID).closest('.comment-reply-form-holder'); const form = $(formID).closest('.comment-reply-form-holder');
$(this).attr('aria-expanded', function (i, attr) { $(this).attr('aria-expanded', (i, attr) => (attr === 'true' ? 'false' : 'true'));
return attr == 'true' ? 'false' : 'true'
});
// Prevent focus // Prevent focus
e.preventDefault(); e.preventDefault();
@ -83,51 +82,49 @@
$('.comments-holder .comments-list').on('click', 'div.comment-moderation-options a', function (e) { $('.comments-holder .comments-list').on('click', 'div.comment-moderation-options a', function (e) {
e.stopPropagation(); e.stopPropagation();
var link = $(this); const link = $(this);
if (link.hasClass('delete')) { if (link.hasClass('delete')) {
var confirmationMsg = ss.i18n._t('CommentsInterface_singlecomment_ss.DELETE_CONFIRMATION'); const confirmationMsg = ss.i18n._t('CommentsInterface_singlecomment_ss.DELETE_CONFIRMATION');
var confirmation = window.confirm(confirmationMsg); const confirmation = window.confirm(confirmationMsg);
if (!confirmation) { if (!confirmation) {
e.preventDefault(); e.preventDefault();
return false; return false;
} }
} }
var comment = link.parents('.comment:first'); const comment = link.parents('.comment:first');
$.ajax({ $.ajax({
url: $(this).attr('href'), url: $(this).attr('href'),
cache: false, cache: false,
success: function(html){ success(html) {
if (link.hasClass('ham')) { if (link.hasClass('ham')) {
// comment has been marked as not spam // comment has been marked as not spam
comment.html(html); comment.html(html);
comment.removeClass('spam'); comment.removeClass('spam');
} } else if (link.hasClass('approve')) {
else if(link.hasClass('approve')) {
// comment has been approved // comment has been approved
comment.html(html); comment.html(html);
comment.removeClass('unmoderated'); comment.removeClass('unmoderated');
} } else if (link.hasClass('delete')) {
else if(link.hasClass('delete')) { comment.fadeOut(1000, () => {
comment.fadeOut(1000, function() {
comment.remove(); comment.remove();
if ($('.comments-holder .comments-list').children().length === 0) { if ($('.comments-holder .comments-list').children().length === 0) {
$('.no-comments-yet').show(); $('.no-comments-yet').show();
} }
}); });
} } else if (link.hasClass('spam')) {
else if(link.hasClass('spam')) {
comment.html(html).addClass('spam'); comment.html(html).addClass('spam');
} }
}, },
failure: function(html) { failure(html) {
var errorMsg = ss.i18n._t('CommentsInterface_singlecomment_ss.AJAX_ERROR'); const errorMsg = ss.i18n._t('CommentsInterface_singlecomment_ss.AJAX_ERROR');
alert(errorMsg); alert(errorMsg);
} }
}); });
e.preventDefault(); e.preventDefault();
return false;
}); });
}); });
})(jQuery); }(jQuery));