From 1f5a7fa7171cffc66547feec645edb91881924cd Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Thu, 20 Mar 2025 10:22:44 +0100 Subject: [PATCH] JS: Use arrow functions All function () {} left in the code reference `this` and thus couldn't use arrow functions. --- adminer/include/design.inc.php | 2 +- adminer/include/functions.inc.php | 2 +- adminer/include/html.inc.php | 2 +- adminer/schema.inc.php | 2 +- adminer/static/editing.js | 10 +++++----- adminer/static/functions.js | 32 ++++++++++++++----------------- editor/static/editing.js | 4 ++-- plugins/codemirror.php | 2 +- plugins/edit-calendar.php | 2 +- plugins/tables-filter.php | 2 +- plugins/tinymce.php | 4 ++-- plugins/version-noverify.php | 2 +- 12 files changed, 31 insertions(+), 35 deletions(-) diff --git a/adminer/include/design.inc.php b/adminer/include/design.inc.php index 9d67fde3..b1c3133e 100644 --- a/adminer/include/design.inc.php +++ b/adminer/include/design.inc.php @@ -76,7 +76,7 @@ const offlineMessage = '" . js_escape(lang('You are offline.')) . "'; const thousandsSeparator = '" . js_escape(lang(',')) . "';") ; echo "\n"; - echo script("mixin(qs('#help'), {onmouseover: function () { helpOpen = 1; }, onmouseout: helpMouseout});"); + echo script("mixin(qs('#help'), {onmouseover: () => { helpOpen = 1; }, onmouseout: helpMouseout});"); echo "
\n"; if ($breadcrumb !== null) { $link = substr(preg_replace('~\b(username|db|ns)=[^&]*&~', '', ME), 0, -1); diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 13923016..4e995ed4 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -974,7 +974,7 @@ function slow_query($query) { $connection2 = null; if (!$slow_query && support("kill") && is_object($connection2 = connect($adminer->credentials())) && ($db == "" || $connection2->select_db($db))) { $kill = $connection2->result(connection_id()); // MySQL and MySQLi can use thread_id but it's not in PDO_MySQL - echo script("const timeout = setTimeout(function () { ajax('" . js_escape(ME) . "script=kill', function () {}, 'kill=$kill&token=$token'); }, 1000 * $timeout);"); + echo script("const timeout = setTimeout(() => { ajax('" . js_escape(ME) . "script=kill', function () {}, 'kill=$kill&token=$token'); }, 1000 * $timeout);"); } ob_flush(); flush(); diff --git a/adminer/include/html.inc.php b/adminer/include/html.inc.php index 51d65c29..a574f115 100644 --- a/adminer/include/html.inc.php +++ b/adminer/include/html.inc.php @@ -150,7 +150,7 @@ function html_radios($name, $options, $value = "") { * @return string */ function confirm($message = "", $selector = "qsl('input')") { - return script("$selector.onclick = function () { return confirm('" . ($message ? js_escape($message) : lang('Are you sure?')) . "'); };", ""); + return script("$selector.onclick = () => confirm('" . ($message ? js_escape($message) : lang('Are you sure?')) . "');", ""); } /** Print header for hidden fieldset (close by
) diff --git a/adminer/schema.inc.php b/adminer/schema.inc.php index 34eb7bb1..fb453388 100644 --- a/adminer/schema.inc.php +++ b/adminer/schema.inc.php @@ -52,7 +52,7 @@ foreach (table_status('', true) as $table => $table_status) { ?>
> -qs('#schema').onselectstart = function () { return false; }; +qs('#schema').onselectstart = () => false; const tablePos = {}; const em = qs('#schema').offsetHeight / ; document.onmousemove = schemaMousemove; diff --git a/adminer/static/editing.js b/adminer/static/editing.js index 66d92b63..9f5d4f21 100644 --- a/adminer/static/editing.js +++ b/adminer/static/editing.js @@ -143,7 +143,7 @@ function dbChange() { */ function selectFieldChange() { const form = this.form; - const ok = (function () { + const ok = (() => { for (const input of qsa('input', form)) { if (input.value && /^fulltext/.test(input.name)) { return true; @@ -523,7 +523,7 @@ function partitionNameChange() { const row = cloneNode(parentTag(this, 'tr')); row.firstChild.firstChild.value = ''; parentTag(this, 'table').appendChild(row); - this.oninput = function () {}; + this.oninput = () => { }; } /** Show or hide comment fields @@ -564,7 +564,7 @@ function dumpClick(event) { */ function foreignAddRow() { const row = cloneNode(parentTag(this, 'tr')); - this.onchange = function () { }; + this.onchange = () => { }; for (const select of qsa('select', row)) { select.name = select.name.replace(/\d+]/, '1$&'); select.selectedIndex = 0; @@ -579,7 +579,7 @@ function foreignAddRow() { */ function indexesAddRow() { const row = cloneNode(parentTag(this, 'tr')); - this.onchange = function () { }; + this.onchange = () => { }; for (const select of qsa('select', row)) { select.name = select.name.replace(/indexes\[\d+/, '$&1'); select.selectedIndex = 0; @@ -781,7 +781,7 @@ function helpMouseover(event, text, side) { function helpMouseout(event) { helpOpen = 0; helpIgnore = (this != getTarget(event)); - setTimeout(function () { + setTimeout(() => { if (!helpOpen) { helpClose(); } diff --git a/adminer/static/functions.js b/adminer/static/functions.js index 12aa03ed..43cb2523 100644 --- a/adminer/static/functions.js +++ b/adminer/static/functions.js @@ -108,13 +108,12 @@ function verifyVersion(current, url, token) { iframe.style.width = '7ex'; iframe.style.height = '1.25em'; iframe.style.display = 'none'; - addEventListener('message', function (event) { + addEventListener('message', event => { if (event.origin == 'https://www.adminer.org') { const match = /version=(.+)/.exec(event.data); if (match) { cookie('adminer_version=' + match[1], 1); - ajax(url + 'script=version', function () { - }, event.data + '&token=' + token); + ajax(url + 'script=version', () => { }, event.data + '&token=' + token); } } }, false); @@ -391,8 +390,7 @@ function selectAddRow() { */ function selectSearchKeydown(event) { if (event.keyCode == 13 || event.keyCode == 10) { - this.onsearch = function () { - }; + this.onsearch = () => { }; } } @@ -498,7 +496,7 @@ function bodyClick(event) { const target = getTarget(event); if ((isCtrl(event) || event.shiftKey) && target.type == 'submit' && isTag(target, 'input')) { target.form.target = '_blank'; - setTimeout(function () { + setTimeout(() => { // if (isCtrl(event)) { focus(); } doesn't work target.form.target = ''; }, 0); @@ -572,7 +570,7 @@ function fieldChange() { } // keep value in