1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-05 14:17:26 +02:00

JS: Use arrow functions

All function () {} left in the code reference `this` and thus couldn't use arrow functions.
This commit is contained in:
Jakub Vrana
2025-03-20 10:22:44 +01:00
parent 3c310ddfaf
commit 1f5a7fa717
12 changed files with 31 additions and 35 deletions

View 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);

View 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();

View 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>)

View 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;

View 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();
}

View 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

View 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);
}

View 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);

View 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']); });");
}
}
}

View 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')){

View 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();
});
};

View File

@@ -9,6 +9,6 @@
class AdminerVersionNoverify {
function head($dark = null) {
echo Adminer\script("verifyVersion = function () {};");
echo Adminer\script("verifyVersion = () => { };");
}
}