1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-08 07:36:44 +02:00

JS: Use let/const in spaghetti code

This commit is contained in:
Jakub Vrana
2025-03-20 08:40:15 +01:00
parent 0e21106e48
commit 101229043e
4 changed files with 16 additions and 17 deletions

View File

@@ -544,7 +544,7 @@ if (!$columns && support("table")) {
echo "<fieldset>";
echo "<legend>" . lang('Whole result') . "</legend>";
$display_rows = ($exact_count ? "" : "~ ") . $found_rows;
$onclick = "var checked = formChecked(this, /check/); selectCount('selected', this.checked ? '$display_rows' : checked); selectCount('selected2', this.checked || !checked ? '$display_rows' : checked);";
$onclick = "const checked = formChecked(this, /check/); selectCount('selected', this.checked ? '$display_rows' : checked); selectCount('selected2', this.checked || !checked ? '$display_rows' : checked);";
echo checkbox("all", 1, 0, ($found_rows !== false ? ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) : ""), $onclick) . "\n";
echo "</fieldset>\n";

View File

@@ -34,7 +34,7 @@ class AdminerEmailTable {
echo "<p>" . ('Attachments') . ": <input type='file' name='email_files[]'>";
echo Adminer\script("qsl('input').onchange = function () {
this.onchange = function () { };
var el = this.cloneNode(true);
const el = this.cloneNode(true);
el.value = '';
this.parentNode.appendChild(el);
};");

View File

@@ -35,8 +35,8 @@ class AdminerSlugify {
if ($slug !== null) {
return "<input value='" . Adminer\h($value) . "' data-maxlength='$field[length]' size='40'$attrs>"
. Adminer\script("qsl('input').onchange = function () {
var find = '$this->from';
var repl = '$this->to';
const find = '$this->from';
const repl = '$this->to';
this.form['fields[$slug]'].value = this.value.toLowerCase()
.replace(new RegExp('[' + find + ']', 'g'), function (str) { return repl[find.indexOf(str)]; })
.replace(/[^a-z0-9_]+/g, '-')

View File

@@ -13,37 +13,36 @@ class AdminerTablesFilter {
var tablesFilterTimeout = null;
var tablesFilterValue = '';
function tablesFilter(){
var value = qs('#filter-field').value.toLowerCase();
function tablesFilter() {
const value = qs('#filter-field').value.toLowerCase();
if (value == tablesFilterValue) {
return;
}
tablesFilterValue = value;
if (value != '') {
var reg = (value + '').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1');
const reg = (value + '').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1');
reg = new RegExp('('+ reg + ')', 'gi');
}
if (sessionStorage) {
sessionStorage.setItem('adminer_tables_filter', value);
}
var tables = qsa('li', qs('#tables'));
for (var i = 0; i < tables.length; i++) {
var a = null;
var text = tables[i].getAttribute('data-table-name');
for (const table of qsa('li', qs('#tables'))) {
let a = null;
let text = table.getAttribute('data-table-name');
if (text == null) {
a = qsa('a', tables[i])[1];
a = qsa('a', table)[1];
text = a.innerHTML.trim();
tables[i].setAttribute('data-table-name', text);
table.setAttribute('data-table-name', text);
a.setAttribute('data-link', 'main');
} else {
a = qs('a[data-link="main"]', tables[i]);
a = qs('a[data-link="main"]', table);
}
if (value == '') {
tables[i].className = '';
table.className = '';
a.innerHTML = text;
} else {
tables[i].className = (text.toLowerCase().indexOf(value) == -1 ? 'hidden' : '');
table.className = (text.toLowerCase().indexOf(value) == -1 ? 'hidden' : '');
a.innerHTML = text.replace(reg, '<strong>$1</strong>');
}
}
@@ -55,7 +54,7 @@ function tablesFilterInput() {
}
sessionStorage && document.addEventListener('DOMContentLoaded', function () {
var db = qs('#dbs').querySelector('select');
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')){
qs('#filter-field').value = sessionStorage.getItem('adminer_tables_filter');