]> git.joonet.de Git - adminer.git/commitdiff
JS: Use arrow functions
authorJakub Vrana <jakub@vrana.cz>
Thu, 20 Mar 2025 09:22:44 +0000 (10:22 +0100)
committerJakub Vrana <jakub@vrana.cz>
Thu, 20 Mar 2025 09:35:08 +0000 (10:35 +0100)
All function () {} left in the code reference `this` and thus couldn't use arrow functions.

12 files changed:
adminer/include/design.inc.php
adminer/include/functions.inc.php
adminer/include/html.inc.php
adminer/schema.inc.php
adminer/static/editing.js
adminer/static/functions.js
editor/static/editing.js
plugins/codemirror.php
plugins/edit-calendar.php
plugins/tables-filter.php
plugins/tinymce.php
plugins/version-noverify.php

index 9d67fde3b32c184e1fb7b680838586e2245fc6f2..b1c3133ed97597758b9783c01421ad92e018539c 100644 (file)
@@ -76,7 +76,7 @@ const offlineMessage = '" . js_escape(lang('You are offline.')) . "';
 const thousandsSeparator = '" . js_escape(lang(',')) . "';")
        ;
        echo "<div id='help' class='jush-" . JUSH . " jsonly hidden'></div>\n";
-       echo script("mixin(qs('#help'), {onmouseover: function () { helpOpen = 1; }, onmouseout: helpMouseout});");
+       echo script("mixin(qs('#help'), {onmouseover: () => { helpOpen = 1; }, onmouseout: helpMouseout});");
        echo "<div id='content'>\n";
        if ($breadcrumb !== null) {
                $link = substr(preg_replace('~\b(username|db|ns)=[^&]*&~', '', ME), 0, -1);
index 13923016ea59c26936a2ad8e2b4d5bb286ac9dc4..4e995ed40feb7382b063fff077cff67fe66d869b 100644 (file)
@@ -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();
index 51d65c29c46c1401848361ca2a522749580a646c..a574f1153d9d34e8c4955f2c432b85cf991fa200 100644 (file)
@@ -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 </div></fieldset>)
index 34eb7bb193954dad352914d41f03533eb0f6bc8c..fb453388bda8a837d7489676875587f9b5456067 100644 (file)
@@ -52,7 +52,7 @@ foreach (table_status('', true) as $table => $table_status) {
 ?>
 <div id="schema" style="height: <?php echo $top; ?>em;">
 <script<?php echo nonce(); ?>>
-qs('#schema').onselectstart = function () { return false; };
+qs('#schema').onselectstart = () => false;
 const tablePos = {<?php echo implode(",", $table_pos_js) . "\n"; ?>};
 const em = qs('#schema').offsetHeight / <?php echo $top; ?>;
 document.onmousemove = schemaMousemove;
index 66d92b63780d03509e835387cc2144a037d46692..9f5d4f21fd65cff733941c10d78d6d83bda7db40 100644 (file)
@@ -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();
                }
index 12aa03ed655d2c20653ea603af89896eae020d92..43cb252367c9c227731fc78de6b7fb8525a0ea3f 100644 (file)
@@ -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 <select> (function)
        parentTag(this, 'table').appendChild(row);
-       this.oninput = function () { };
+       this.oninput = () => { };
 }
 
 
@@ -600,7 +598,7 @@ function ajax(url, callback, data, message) {
                        request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                }
                request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
-               request.onreadystatechange = function () {
+               request.onreadystatechange = () => {
                        if (request.readyState == 4) {
                                if (/^2/.test(request.status)) {
                                        callback(request);
@@ -620,7 +618,7 @@ function ajax(url, callback, data, message) {
 * @return boolean false for success
 */
 function ajaxSetHtml(url) {
-       return !ajax(url, function (request) {
+       return !ajax(url, request => {
                const data = JSON.parse(request.responseText);
                for (const key in data) {
                        setHtml(key, data[key]);
@@ -653,7 +651,7 @@ function ajaxForm(form, message, button) {
                url = url.replace(/\?.*/, '') + '?' + data;
                data = '';
        }
-       return ajax(url, function (request) {
+       return ajax(url, request => {
                setHtml('ajaxstatus', request.responseText);
                if (window.jush) {
                        jush.highlight_tag(qsa('code', qs('#ajaxstatus')), 0);
@@ -684,7 +682,7 @@ function selectClick(event, text, warning) {
        const original = td.innerHTML;
        text = text || /\n/.test(original);
        const input = document.createElement(text ? 'textarea' : 'input');
-       input.onkeydown = function (event) {
+       input.onkeydown = event => {
                if (!event) {
                        event = window.event;
                }
@@ -702,7 +700,7 @@ function selectClick(event, text, warning) {
 
        if (text) {
                let rows = 1;
-               value.replace(/\n/g, function () {
+               value.replace(/\n/g, () => {
                        rows++;
                });
                input.rows = rows;
@@ -723,7 +721,7 @@ function selectClick(event, text, warning) {
        setupSubmitHighlight(td);
        input.focus();
        if (text == 2) { // long text
-               return ajax(location.href + '&' + encodeURIComponent(td.id) + '=', function (request) {
+               return ajax(location.href + '&' + encodeURIComponent(td.id) + '=', request => {
                        if (request.responseText) {
                                input.value = request.responseText;
                                input.name = td.id;
@@ -757,16 +755,14 @@ function selectLoadMore(limit, loading) {
        a.innerHTML = loading;
        if (href) {
                a.removeAttribute('href');
-               return !ajax(href, function (request) {
+               return !ajax(href, request => {
                        const tbody = document.createElement('tbody');
                        tbody.innerHTML = request.responseText;
                        qs('#table').appendChild(tbody);
                        if (tbody.children.length < limit) {
                                a.parentNode.removeChild(a);
                        } else {
-                               a.href = href.replace(/\d+$/, function (page) {
-                                       return +page + 1;
-                               });
+                               a.href = href.replace(/\d+$/, page => +page + 1);
                                a.innerHTML = title;
                        }
                });
@@ -883,7 +879,7 @@ function cloneNode(el) {
        return el2;
 }
 
-oninput = function (event) {
+oninput = event => {
        const target = event.target;
        const maxLength = target.getAttribute('data-maxlength');
        alterClass(target, 'maxlength', target.value && maxLength != null && target.value.length > maxLength); // maxLength could be 0
index 531e56d453ddd8a24f097619d2b49512f4f70a36..0d153fde96349878e23c3459f25afadd24645b09 100644 (file)
@@ -25,7 +25,7 @@ function whisper(url) {
        const field = this;
        field.orig = field.value;
        field.previousSibling.value = field.value; // accept number, reject string
-       return ajax(url + encodeURIComponent(field.value), function (xmlhttp) {
+       return ajax(url + encodeURIComponent(field.value), xmlhttp => {
                if (xmlhttp.status && field.orig == field.value) { // ignore old responses
                        field.nextSibling.innerHTML = xmlhttp.responseText;
                        field.nextSibling.style.display = '';
@@ -59,7 +59,7 @@ function whisperClick(event) {
 */
 function emailFileChange() {
        const el = this.cloneNode(true);
-       this.onchange = function () { };
+       this.onchange = () => { };
        el.value = '';
        this.parentNode.appendChild(el);
 }
index 8d55988c136e44fd86094e7d06751b633a2bb25c..ed5fdb24abc956646ef8ce597ed31eee219b89b5 100644 (file)
@@ -76,7 +76,7 @@ for (const el of qsa('textarea')) {
                        }
                });
                cm.setSize(width, height);
-               cm.on('inputRead', function () {
+               cm.on('inputRead', () => {
                        const token = cm.getTokenAt(cm.getCursor());
                        if (/^[.`"\w]\w*$/.test(token.string)) {
                                CodeMirror.commands.autocomplete(cm);
index 09cd88cb154c9af0be27eb22067234ac567a2531..466e7a5870ebb85bdf86c3220d5b25ef52af6d10 100644 (file)
@@ -34,7 +34,7 @@ class AdminerEditCalendar {
                        $lang = ($lang == "zh" ? "zh-CN" : ($lang == "zh-tw" ? "zh-TW" : $lang));
                        if ($lang != "en" && file_exists(sprintf($this->langPath, $lang))) {
                                echo Adminer\script_src(sprintf($this->langPath, $lang));
-                               echo Adminer\script("jQuery(function () { jQuery.timepicker.setDefaults(jQuery.datepicker.regional['$lang']); });");
+                               echo Adminer\script("jQuery(() => { jQuery.timepicker.setDefaults(jQuery.datepicker.regional['$lang']); });");
                        }
                }
        }
index 97334602a9df766200450efa9143c61f4e153457..52675d4c7e664ffabb65dcf829fd1e10a12019b8 100644 (file)
@@ -53,7 +53,7 @@ function tablesFilterInput() {
        tablesFilterTimeout = window.setTimeout(tablesFilter, 200);
 }
 
-sessionStorage && document.addEventListener('DOMContentLoaded', function () {
+sessionStorage && document.addEventListener('DOMContentLoaded', () => {
        let db = qs('#dbs').querySelector('select');
        db = db.options[db.selectedIndex].text;
        if (db == sessionStorage.getItem('adminer_tables_filter_db') && sessionStorage.getItem('adminer_tables_filter')){
index 5695b9a282209c02caa1d9af7dbbb5f5a899d8a4..730b735eac8b28ecd98ba98a2aad4a4633ba9770 100644 (file)
@@ -61,8 +61,8 @@ tinyMCE.init({
                        return "<textarea$attrs id='fields-" . Adminer\h($field["field"]) . "' rows='12' cols='50'>" . Adminer\h($value) . "</textarea>" . Adminer\script("
 tinyMCE.remove(tinyMCE.get('fields-" . Adminer\js_escape($field["field"]) . "') || { });
 tinyMCE.EditorManager.execCommand('mceAddControl', true, 'fields-" . Adminer\js_escape($field["field"]) . "');
-qs('#form').onsubmit = function () {
-       tinyMCE.each(tinyMCE.editors, function (ed) {
+qs('#form').onsubmit = () => {
+       tinyMCE.each(tinyMCE.editors, ed => {
                ed.remove();
        });
 };
index 3d83384a62600dbfad5dd73c40c1afb16268ea89..f01759a7baa855b8927af2e127c957bacdf4fee0 100644 (file)
@@ -9,6 +9,6 @@
 class AdminerVersionNoverify {
 
        function head($dark = null) {
-               echo Adminer\script("verifyVersion = function () {};");
+               echo Adminer\script("verifyVersion = () => { };");
        }
 }