1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-06 00:37:42 +02:00

[ticket/17517] Update and refactor eslint implementation

PHPBB-17517
This commit is contained in:
Matt Friedman
2025-06-26 18:25:05 -07:00
parent 9adb7eb9fe
commit 158a561651
14 changed files with 1356 additions and 847 deletions

View File

@@ -1,4 +1,6 @@
/* global bbfontstyle */
/* eslint no-var: 0 */
/* eslint no-unused-vars: 0 */
var phpbb = {};
phpbb.alertTime = 100;
@@ -13,7 +15,7 @@ var keymap = {
ENTER: 13,
ESC: 27,
ARROW_UP: 38,
ARROW_DOWN: 40
ARROW_DOWN: 40,
};
var $dark = $('#darkenwrapper');
@@ -54,7 +56,7 @@ phpbb.loadingIndicator = function() {
/**
* Show timeout message
*/
phpbb.showTimeoutMessage = function () {
phpbb.showTimeoutMessage = function() {
var $alert = $('#phpbb_alert');
if ($loadingIndicator.is(':visible')) {
@@ -363,7 +365,7 @@ phpbb.ajaxify = function(options) {
type: 'POST',
data: data + '&confirm=' + res.YES_VALUE + '&' + $('form', '#phpbb_confirm').serialize(),
success: returnHandler,
error: errorHandler
error: errorHandler,
});
}, false);
}
@@ -383,7 +385,7 @@ phpbb.ajaxify = function(options) {
submit = $this.find('input[type="submit"][data-clicked]');
data.push({
name: submit.attr('name'),
value: submit.val()
value: submit.val(),
});
}
} else if (isText) {
@@ -409,7 +411,7 @@ phpbb.ajaxify = function(options) {
data: data,
success: returnHandler,
error: errorHandler,
cache: false
cache: false,
});
request.always(function() {
@@ -430,7 +432,7 @@ phpbb.ajaxify = function(options) {
});
if (isForm) {
$elements.find('input:submit').click(function () {
$elements.find('input:submit').click(function() {
var $this = $(this);
// Remove data-clicked attribute from any submit button of form
@@ -445,10 +447,10 @@ phpbb.ajaxify = function(options) {
phpbb.search = {
cache: {
data: []
data: [],
},
tpl: [],
container: []
container: [],
};
/**
@@ -524,7 +526,7 @@ phpbb.search.getKeyword = function($input, keyword, multiline) {
* @param {jQuery} $textarea Search textarea.
* @returns {int} The line number.
*/
phpbb.search.getKeywordLine = function ($textarea) {
phpbb.search.getKeywordLine = function($textarea) {
var selectionStart = $textarea.get(0).selectionStart;
return $textarea.val().substr(0, selectionStart).split('\n').length - 1;
};
@@ -609,7 +611,7 @@ phpbb.search.filter = function(data, event, sendRequest) {
if (cache.results[keyword]) {
var response = {
keyword: keyword,
results: cache.results[keyword]
results: cache.results[keyword],
};
phpbb.search.handleResponse(response, $this, true);
proceed = false;
@@ -1079,7 +1081,7 @@ phpbb.addAjaxCallback('toggle_link', function() {
$this.attr('href', toggleUrl);
// Toggle Icon
$this.children().first().toggleClass('is-active').next().toggleClass('is-active')
$this.children().first().toggleClass('is-active').next().toggleClass('is-active');
});
});
@@ -1113,7 +1115,7 @@ phpbb.resizeTextArea = function($items, options) {
maxHeight: 500,
heightDiff: 200,
resizeCallback: function() {},
resetCallback: function() {}
resetCallback: function() {},
};
if (phpbb.isTouch) {
@@ -1152,7 +1154,7 @@ phpbb.resizeTextArea = function($items, options) {
var maxHeight = Math.min(
Math.max(windowHeight - configuration.heightDiff, configuration.minHeight),
configuration.maxHeight
configuration.maxHeight,
),
$item = $(item),
height = parseInt($item.innerHeight(), 10),
@@ -1243,9 +1245,9 @@ phpbb.inBBCodeTag = function(textarea, startTags, endTags) {
*/
phpbb.applyCodeEditor = function(textarea) {
// list of allowed start and end bbcode code tags, in lower case
var startTags = ['[code]', '[code='],
var startTags = [ '[code]', '[code=' ],
startTagsEnd = ']',
endTags = ['[/code]'];
endTags = [ '[/code]' ];
if (!textarea || typeof textarea.selectionStart !== 'number') {
return;
@@ -1353,12 +1355,12 @@ phpbb.showDragNDrop = function(textarea) {
return;
}
$('body').on('dragenter dragover', function () {
$('body').on('dragenter dragover', function() {
$(textarea).addClass('drag-n-drop');
}).on('dragleave dragout dragend drop', function() {
$(textarea).removeClass('drag-n-drop');
});
$(textarea).on('dragenter dragover', function () {
$(textarea).on('dragenter dragover', function() {
$(textarea).addClass('drag-n-drop-highlight');
}).on('dragleave dragout dragend drop', function() {
$(textarea).removeClass('drag-n-drop-highlight');
@@ -1434,7 +1436,7 @@ phpbb.toggleDropdown = function(event_) {
marginLeft: 0,
left: 0,
marginRight: 0,
maxWidth: (windowWidth - 4) + 'px'
maxWidth: (windowWidth - 4) + 'px',
});
var offset = $this.offset().left,
@@ -1468,7 +1470,7 @@ phpbb.toggleDropdown = function(event_) {
var maxOffset = Math.min(contentWidth, fullFreeSpace) + 'px';
options.dropdown.css({
width: maxOffset,
marginLeft: -maxOffset
marginLeft: -maxOffset,
});
}
} else {
@@ -1512,7 +1514,7 @@ phpbb.registerDropdown = function(toggle, dropdown, options) {
leftClass: 'dropdown-left', // Class to add to parent item when dropdown opens to left side
rightClass: 'dropdown-right', // Class to add to parent item when dropdown opens to right side
upClass: 'dropdown-up', // Class to add to parent item when dropdown opens above menu item
downClass: 'dropdown-down' // Class to add to parent item when dropdown opens below menu item
downClass: 'dropdown-down', // Class to add to parent item when dropdown opens below menu item
};
if (options) {
ops = $.extend(ops, options);
@@ -1666,7 +1668,7 @@ phpbb.toggleSelectSettings = function(el) {
* @param {string} functionName Function to get.
* @returns function
*/
phpbb.getFunctionByName = function (functionName) {
phpbb.getFunctionByName = function(functionName) {
var namespaces = functionName.split('.'),
func = namespaces.pop(),
context = window;
@@ -1716,7 +1718,7 @@ phpbb.registerPageDropdowns = function() {
$contents = $this.find('.dropdown'),
options = {
direction: 'auto',
verticalDirection: 'auto'
verticalDirection: 'auto',
},
data;
@@ -1763,7 +1765,7 @@ phpbb.registerPageDropdowns = function() {
* Handle avatars to be lazy loaded.
*/
phpbb.lazyLoadAvatars = function loadAvatars() {
$('.avatar[data-src]').each(function () {
$('.avatar[data-src]').each(function() {
var $avatar = $(this);
$avatar
@@ -1795,7 +1797,7 @@ phpbb.getEditorTextArea = function(formName, textareaName) {
}
return doc.forms[formName].elements[textareaName];
}
};
phpbb.recaptcha = {
button: null,
@@ -1826,7 +1828,7 @@ phpbb.recaptcha = {
if (phpbb.recaptcha.v3.length) {
grecaptcha.execute(
phpbb.recaptcha.v3.data('recaptcha-v3'),
{action: phpbb.recaptcha.v3.val()}
{ action: phpbb.recaptcha.v3.val() },
).then(function(token) {
// Place the token inside the form
phpbb.recaptcha.token.val(token);
@@ -1860,7 +1862,7 @@ phpbb.recaptcha = {
phpbb.recaptcha.form.submit();
}
}
},
};
// reCAPTCHA v2 doesn't accept callback functions nested inside objects

View File

@@ -1,4 +1,8 @@
/* global phpbb */
/* eslint camelcase: 0 */
/* eslint no-undef: 0 */
/* eslint no-unused-vars: 0 */
/* eslint no-var: 0 */
/**
* bbCode control by subBlue design [ www.subBlue.com ]
@@ -100,7 +104,7 @@ function bbfontstyle(bbopen, bbclose) {
// IE
else if (document.selection) {
var range = textarea.createTextRange();
range.move("character", new_pos);
range.move('character', new_pos);
range.select();
storeCaret(textarea);
}
@@ -271,7 +275,7 @@ function formatAttributeValue(str) {
// Return as-is if it contains none of: space, ' " \ or ]
return str;
}
var singleQuoted = "'" + str.replace(/[\\']/g, '\\$&') + "'",
var singleQuoted = '\'' + str.replace(/[\\']/g, '\\$&') + '\'',
doubleQuoted = '"' + str.replace(/[\\"]/g, '\\$&') + '"';
return (singleQuoted.length < doubleQuoted.length) ? singleQuoted : doubleQuoted;
@@ -404,7 +408,7 @@ function getCaretPosition(txtarea) {
phpbb.showDragNDrop(textarea);
}
$('textarea').on('keydown', function (e) {
$('textarea').on('keydown', function(e) {
if (e.which === 13 && (e.metaKey || e.ctrlKey)) {
$(this).closest('form').find(':submit').click();
}

View File

@@ -2,6 +2,9 @@
* Installer's AJAX frontend handler
*/
/* eslint no-prototype-builtins: 0 */
/* eslint no-var: 0 */
(function($) { // Avoid conflicts with other libraries
'use strict';
@@ -359,10 +362,10 @@
} else {
$('#loading_indicator').css('display', 'none');
addMessage('error',
[{
[ {
title: installLang.title,
description: installLang.msg
}]
description: installLang.msg,
} ],
);
}
}
@@ -487,7 +490,7 @@
function startPolling(xhReq) {
resetPolling();
transmissionOver = false;
pollTimer = setInterval(function () {
pollTimer = setInterval(function() {
pollContent(xhReq);
}, 250);
}
@@ -609,7 +612,7 @@
setAdminTimezone($form);
}
$form.find(':submit').bind('click', function (event) {
$form.find(':submit').bind('click', function(event) {
event.preventDefault();
submitForm($form, $(this));
});

View File

@@ -1,4 +1,7 @@
/* global phpbb, plupload, attachInline */
/* eslint camelcase: 0 */
/* eslint no-var: 0 */
/* eslint no-unused-vars: 0 */
plupload.addI18n(phpbb.plupload.i18n);
phpbb.plupload.ids = [];
@@ -21,7 +24,7 @@ phpbb.plupload.initialize = function() {
// Only execute if Plupload initialized successfully.
phpbb.plupload.uploader.bind('Init', function() {
phpbb.plupload.form = $(phpbb.plupload.config.form_hook)[0];
let $attachRowTemplate = $('#attach-row-tpl');
const $attachRowTemplate = $('#attach-row-tpl');
$attachRowTemplate.removeClass('attach-row-tpl');
phpbb.plupload.rowTpl = $attachRowTemplate[0].outerHTML;
@@ -300,7 +303,7 @@ phpbb.plupload.deleteFile = function(row, attachId) {
$.ajax(phpbb.plupload.config.url, {
type: 'POST',
data: $.extend(fields, phpbb.plupload.getSerializedData()),
headers: phpbb.plupload.config.headers
headers: phpbb.plupload.config.headers,
})
.always(always)
.done(done);
@@ -452,7 +455,7 @@ phpbb.plupload.fileError = function(file, error) {
.addClass('file-error')
.attr({
'data-error-title': phpbb.plupload.lang.ERROR,
'data-error-message': error
'data-error-message': error,
});
};
@@ -469,14 +472,14 @@ phpbb.plupload.initialize();
plupload.addFileFilter('mime_types_max_file_size', function(types, file, callback) {
if (file.size !== 'undefined') {
$(types).each(function(i, type) {
let extensions = [],
const extensions = [],
extsArray = type.extensions.split(',');
$(extsArray).each(function(i, extension) {
/^\s*\*\s*$/.test(extension) ? extensions.push("\\.*") : extensions.push("\\." + extension.replace(new RegExp("[" + "/^$.*+?|()[]{}\\".replace(/./g, "\\$&") + "]", "g"), "\\$&"));
/^\s*\*\s*$/.test(extension) ? extensions.push('\\.*') : extensions.push('\\.' + extension.replace(new RegExp('[' + '/^$.*+?|()[]{}\\'.replace(/./g, '\\$&') + ']', 'g'), '\\$&'));
});
let regex = new RegExp("(" + extensions.join("|") + ")$", "i");
const regex = new RegExp('(' + extensions.join('|') + ')$', 'i');
if (regex.test(file.name)) {
if (type.max_file_size !== 'undefined' && type.max_file_size) {
@@ -484,7 +487,7 @@ plupload.addFileFilter('mime_types_max_file_size', function(types, file, callbac
phpbb.plupload.uploader.trigger('Error', {
code: plupload.FILE_SIZE_ERROR,
message: plupload.translate('File size error.'),
file: file
file: file,
});
callback(false);
@@ -587,9 +590,9 @@ phpbb.plupload.uploader.bind('ChunkUploaded', function(up, file, response) {
up.trigger('FileUploaded', file, {
response: JSON.stringify({
error: {
message: 'Error parsing server response.'
}
})
message: 'Error parsing server response.',
},
}),
});
}
@@ -603,9 +606,9 @@ phpbb.plupload.uploader.bind('ChunkUploaded', function(up, file, response) {
up.trigger('FileUploaded', file, {
response: JSON.stringify({
error: {
message: json.error.message
}
})
message: json.error.message,
},
}),
});
}
});
@@ -692,7 +695,7 @@ phpbb.plupload.uploader.bind('FileUploaded', function(up, file, response) {
row.attr('data-attach-id', file.attachment_data.attach_id);
row.find('.file-inline-bbcode').show();
row.find('.file-status').addClass('file-uploaded');
phpbb.plupload.update(json.data, 'addition', 0, [json.download_url]);
phpbb.plupload.update(json.data, 'addition', 0, [ json.download_url ]);
}
});