]> git.joonet.de Git - adminer.git/commitdiff
JS: Change var to let/const
authorJakub Vrana <jakub@vrana.cz>
Thu, 20 Mar 2025 07:32:23 +0000 (08:32 +0100)
committerJakub Vrana <jakub@vrana.cz>
Thu, 20 Mar 2025 07:32:23 +0000 (08:32 +0100)
Created by `eslint . --fix` with rules no-var and then prefer-const.

adminer/static/editing.js
adminer/static/functions.js
editor/static/editing.js

index d799d8f9f55e34eefe86b09ee2ec148b908e7d1b..e368bc86c61e11ab2e2555a6bc9af519e2a30a0f 100644 (file)
@@ -8,13 +8,13 @@ function syntaxHighlighting(version, vendor) {
        if (window.jush) {
                jush.create_links = ' target="_blank" rel="noreferrer noopener"';
                if (version) {
-                       for (var key in jush.urls) {
-                               var obj = jush.urls;
+                       for (let key in jush.urls) {
+                               let obj = jush.urls;
                                if (typeof obj[key] != 'string') {
                                        obj = obj[key];
                                        key = 0;
                                        if (vendor == 'maria') {
-                                               for (var i = 1; i < obj.length; i++) {
+                                               for (let i = 1; i < obj.length; i++) {
                                                        obj[i] = obj[i]
                                                                .replace('.html', '/')
                                                                .replace('-type-syntax', '-data-types')
@@ -43,7 +43,7 @@ function syntaxHighlighting(version, vendor) {
                jush.highlight_tag('code', 0);
                for (const tag of qsa('textarea')) {
                        if (/(^|\s)jush-/.test(tag.className)) {
-                               var pre = jush.textarea(tag);
+                               const pre = jush.textarea(tag);
                                if (pre) {
                                        setupSubmitHighlightInput(pre);
                                }
@@ -59,7 +59,7 @@ function syntaxHighlighting(version, vendor) {
 */
 function formField(form, name) {
        // required in IE < 8, form.elements[name] doesn't work
-       for (var i=0; i < form.length; i++) {
+       for (let i=0; i < form.length; i++) {
                if (form[i].name == name) {
                        return form[i];
                }
@@ -92,16 +92,16 @@ function messagesPrint(parent) {
 * @param HTMLSelectElement
 */
 function loginDriver(driver) {
-       var trs = parentTag(driver, 'table').rows;
-       var disabled = /sqlite/.test(selectValue(driver));
+       const trs = parentTag(driver, 'table').rows;
+       const disabled = /sqlite/.test(selectValue(driver));
        alterClass(trs[1], 'hidden', disabled); // 1 - row with server
        trs[1].getElementsByTagName('input')[0].disabled = disabled;
 }
 
 
 
-var dbCtrl;
-var dbPrevious = {};
+let dbCtrl;
+const dbPrevious = {};
 
 /** Check if database should be opened to a new window
 * @param MouseEvent
@@ -142,22 +142,22 @@ function dbChange() {
 * @this HTMLElement
 */
 function selectFieldChange() {
-       var form = this.form;
-       var ok = (function () {
+       const form = this.form;
+       const ok = (function () {
                for (const input of qsa('input', form)) {
                        if (input.value && /^fulltext/.test(input.name)) {
                                return true;
                        }
                }
-               var ok = form.limit.value;
-               var group = false;
-               var columns = {};
+               let ok = form.limit.value;
+               let group = false;
+               const columns = {};
                for (const select of qsa('select', form)) {
-                       var col = selectValue(select);
-                       var match = /^(where.+)col]/.exec(select.name);
+                       const col = selectValue(select);
+                       let match = /^(where.+)col]/.exec(select.name);
                        if (match) {
-                               var op = selectValue(form[match[1] + 'op]']);
-                               var val = form[match[1] + 'val]'].value;
+                               const op = selectValue(form[match[1] + 'op]']);
+                               const val = form[match[1] + 'val]'].value;
                                if (col in indexColumns && (!/LIKE|REGEXP/.test(op) || (op == 'LIKE' && val.charAt(0) != '%'))) {
                                        return true;
                                } else if (col || val) {
@@ -168,7 +168,7 @@ function selectFieldChange() {
                                if (/^(avg|count|count distinct|group_concat|max|min|sum)$/.test(col)) {
                                        group = true;
                                }
-                               var val = selectValue(form[match[1] + 'col]']);
+                               const val = selectValue(form[match[1] + 'col]']);
                                if (val) {
                                        columns[col && col != 'count' ? '' : val] = 1;
                                }
@@ -181,7 +181,7 @@ function selectFieldChange() {
                        }
                }
                if (group) {
-                       for (var col in columns) {
+                       for (const col in columns) {
                                if (!(col in indexColumns)) {
                                        ok = false;
                                }
@@ -194,7 +194,7 @@ function selectFieldChange() {
 
 
 
-var added = '.', rowCount;
+let added = '.', rowCount;
 
 /** Check if val is equal to a-delimiter-b where delimiter is '_', '' or big letter
 * @param string
@@ -249,13 +249,13 @@ function editFields() {
 * @return boolean false to cancel action
 */
 function editingClick(event) {
-       var el = getTarget(event);
+       let el = getTarget(event);
        if (!isTag(el, 'input')) {
                el = parentTag(el, 'label');
                el = el && qs('input', el);
        }
        if (el) {
-               var name = el.name;
+               const name = el.name;
                if (/^add\[/.test(name)) {
                        editingAddRow.call(el, 1);
                } else if (/^up\[/.test(name)) {
@@ -266,7 +266,7 @@ function editingClick(event) {
                        editingRemoveRow.call(el, 'fields$1[field]');
                } else {
                        if (name == 'auto_increment_col') {
-                               var field = el.form['fields[' + el.value + '][field]'];
+                               const field = el.form['fields[' + el.value + '][field]'];
                                if (!field.value) {
                                        field.value = 'id';
                                        field.oninput();
@@ -282,7 +282,7 @@ function editingClick(event) {
 * @param InputEvent
 */
 function editingInput(event) {
-       var el = getTarget(event);
+       const el = getTarget(event);
        if (/\[default]$/.test(el.name)) {
                 el.previousElementSibling.checked = true;
                 el.previousElementSibling.selectedIndex = Math.max(el.previousElementSibling.selectedIndex, 1);
@@ -293,21 +293,21 @@ function editingInput(event) {
 * @this HTMLInputElement
 */
 function editingNameChange() {
-       var name = this.name.substr(0, this.name.length - 7);
-       var type = formField(this.form, name + '[type]');
-       var opts = type.options;
-       var candidate; // don't select anything with ambiguous match (like column `id`)
-       var val = this.value;
-       for (var i = opts.length; i--; ) {
-               var match = /(.+)`(.+)/.exec(opts[i].value);
+       const name = this.name.substr(0, this.name.length - 7);
+       const type = formField(this.form, name + '[type]');
+       const opts = type.options;
+       let candidate; // don't select anything with ambiguous match (like column `id`)
+       const val = this.value;
+       for (let i = opts.length; i--; ) {
+               const match = /(.+)`(.+)/.exec(opts[i].value);
                if (!match) { // common type
                        if (candidate && i == opts.length - 2 && val == opts[candidate].value.replace(/.+`/, '') && name == 'fields[1]') { // single target table, link to column, first field - probably `id`
                                return;
                        }
                        break;
                }
-               var base = match[1];
-               var column = match[2];
+               const base = match[1];
+               const column = match[2];
                for (const table of [ base, base.replace(/s$/, ''), base.replace(/es$/, '') ]) {
                        if (val == column || val == table || delimiterEqual(val, table, column) || delimiterEqual(val, column, table)) {
                                if (candidate) {
@@ -330,20 +330,20 @@ function editingNameChange() {
 * @this HTMLInputElement
 */
 function editingAddRow(focus) {
-       var match = /(\d+)(\.\d+)?/.exec(this.name);
-       var x = match[0] + (match[2] ? added.substr(match[2].length) : added) + '1';
-       var row = parentTag(this, 'tr');
-       var row2 = cloneNode(row);
-       var tags = qsa('select', row);
-       var tags2 = qsa('select', row2);
-       for (var i=0; i < tags.length; i++) {
+       const match = /(\d+)(\.\d+)?/.exec(this.name);
+       const x = match[0] + (match[2] ? added.substr(match[2].length) : added) + '1';
+       const row = parentTag(this, 'tr');
+       const row2 = cloneNode(row);
+       let tags = qsa('select', row);
+       let tags2 = qsa('select', row2);
+       for (let i=0; i < tags.length; i++) {
                tags2[i].name = tags[i].name.replace(/[0-9.]+/, x);
                tags2[i].selectedIndex = tags[i].selectedIndex;
        }
        tags = qsa('input', row);
        tags2 = qsa('input', row2);
-       var input = tags2[0]; // IE loose tags2 after insertBefore()
-       for (var i=0; i < tags.length; i++) {
+       const input = tags2[0]; // IE loose tags2 after insertBefore()
+       for (let i=0; i < tags.length; i++) {
                if (tags[i].name == 'auto_increment_col') {
                        tags2[i].value = x;
                        tags2[i].checked = false;
@@ -374,7 +374,7 @@ function editingAddRow(focus) {
 * @this HTMLInputElement
 */
 function editingRemoveRow(name) {
-       var field = formField(this.form, this.name.replace(/[^[]+(.+)/, name));
+       const field = formField(this.form, this.name.replace(/[^[]+(.+)/, name));
        field.parentNode.removeChild(field);
        parentTag(this, 'tr').style.display = 'none';
        return false;
@@ -386,7 +386,7 @@ function editingRemoveRow(name) {
 * @this HTMLInputElement
 */
 function editingMoveRow(up){
-       var row = parentTag(this, 'tr');
+       const row = parentTag(this, 'tr');
        if (!('nextElementSibling' in row)) {
                return true;
        }
@@ -402,9 +402,9 @@ var lastType = '';
 * @this HTMLSelectElement
 */
 function editingTypeChange() {
-       var type = this;
-       var name = type.name.substr(0, type.name.length - 6);
-       var text = selectValue(type);
+       const type = this;
+       const name = type.name.substr(0, type.name.length - 6);
+       const text = selectValue(type);
        for (const el of type.form.elements.length) {
                if (el.name == name + '[length]') {
                        if (!(
@@ -446,9 +446,9 @@ function editingLengthChange() {
 * @this HTMLInputElement
 */
 function editingLengthFocus() {
-       var td = this.parentNode;
+       const td = this.parentNode;
        if (/(enum|set)$/.test(selectValue(td.previousSibling.firstChild))) {
-               var edit = qs('#enum-edit');
+               const edit = qs('#enum-edit');
                edit.value = enumValues(this.value);
                td.appendChild(edit);
                this.style.display = 'none';
@@ -462,10 +462,10 @@ function editingLengthFocus() {
 * @return string values separated by newlines
 */
 function enumValues(s) {
-       var re = /(^|,)\s*'(([^\\']|\\.|'')*)'\s*/g;
-       var result = [];
-       var offset = 0;
-       var match;
+       const re = /(^|,)\s*'(([^\\']|\\.|'')*)'\s*/g;
+       const result = [];
+       let offset = 0;
+       let match;
        while ((match = re.exec(s))) {
                if (offset != match.index) {
                        break;
@@ -480,8 +480,8 @@ function enumValues(s) {
 * @this HTMLTextAreaElement
 */
 function editingLengthBlur() {
-       var field = this.parentNode.firstChild;
-       var val = this.value;
+       const field = this.parentNode.firstChild;
+       const val = this.value;
        field.value = (/^'[^\n]+'$/.test(val) ? val : val && "'" + val.replace(/\n+$/, '').replace(/'/g, "''").replace(/\\/g, '\\\\').replace(/\n/g, "','") + "'");
        field.style.display = 'inline';
        this.style.display = 'none';
@@ -510,7 +510,7 @@ function indexOptionsShow(checked) {
 * @this HTMLSelectElement
 */
 function partitionByChange() {
-       var partitionTable = /RANGE|LIST/.test(selectValue(this));
+       const partitionTable = /RANGE|LIST/.test(selectValue(this));
        alterClass(this.form['partitions'], 'hidden', partitionTable || !this.selectedIndex);
        alterClass(qs('#partition-table'), 'hidden', !partitionTable);
        helpClose();
@@ -520,7 +520,7 @@ function partitionByChange() {
 * @this HTMLInputElement
 */
 function partitionNameChange() {
-       var row = cloneNode(parentTag(this, 'tr'));
+       const row = cloneNode(parentTag(this, 'tr'));
        row.firstChild.firstChild.value = '';
        parentTag(this, 'table').appendChild(row);
        this.oninput = function () {};
@@ -531,7 +531,7 @@ function partitionNameChange() {
 * @param [boolean] whether to focus Comment if checked
 */
 function editingCommentsClick(el, focus) {
-       var comment = el.form['Comment'];
+       const comment = el.form['Comment'];
        columnShow(el.checked, 6);
        alterClass(comment, 'hidden', !el.checked);
        if (focus && el.checked) {
@@ -546,10 +546,10 @@ function editingCommentsClick(el, focus) {
 * @this HTMLTableElement
 */
 function dumpClick(event) {
-       var el = parentTag(getTarget(event), 'label');
+       let el = parentTag(getTarget(event), 'label');
        if (el) {
                el = qs('input', el);
-               var match = /(.+)\[]$/.exec(el.name);
+               const match = /(.+)\[]$/.exec(el.name);
                if (match) {
                        checkboxClick.call(el, event);
                        formUncheck('check-' + match[1]);
@@ -563,7 +563,7 @@ function dumpClick(event) {
 * @this HTMLSelectElement
 */
 function foreignAddRow() {
-       var row = cloneNode(parentTag(this, 'tr'));
+       const row = cloneNode(parentTag(this, 'tr'));
        this.onchange = function () { };
        for (const select of qsa('select', row)) {
                select.name = select.name.replace(/\d+]/, '1$&');
@@ -578,7 +578,7 @@ function foreignAddRow() {
 * @this HTMLSelectElement
 */
 function indexesAddRow() {
-       var row = cloneNode(parentTag(this, 'tr'));
+       const row = cloneNode(parentTag(this, 'tr'));
        this.onchange = function () { };
        for (const select of qsa('select', row)) {
                select.name = select.name.replace(/indexes\[\d+/, '$&1');
@@ -596,11 +596,11 @@ function indexesAddRow() {
 * @this HTMLSelectElement
 */
 function indexesChangeColumn(prefix) {
-       var names = [];
-       for (var tag in { 'select': 1, 'input': 1 }) {
+       const names = [];
+       for (const tag in { 'select': 1, 'input': 1 }) {
                for (const column of qsa(tag, parentTag(this, 'td'))) {
                        if (/\[columns]/.test(column.name)) {
-                               var value = selectValue(column);
+                               const value = selectValue(column);
                                if (value) {
                                        names.push(value);
                                }
@@ -615,15 +615,15 @@ function indexesChangeColumn(prefix) {
 * @this HTMLSelectElement
 */
 function indexesAddColumn(prefix) {
-       var field = this;
-       var select = field.form[field.name.replace(/].*/, '][type]')];
+       const field = this;
+       const select = field.form[field.name.replace(/].*/, '][type]')];
        if (!select.selectedIndex) {
                while (selectValue(select) != "INDEX" && select.selectedIndex < select.options.length) {
                        select.selectedIndex++;
                }
                select.onchange();
        }
-       var column = cloneNode(field.parentNode);
+       const column = cloneNode(field.parentNode);
        for (const select of qsa('select', column)) {
                select.name = select.name.replace(/]\[\d+/, '$&1');
                select.selectedIndex = 0;
@@ -664,7 +664,7 @@ function sqlSubmit(form, root) {
 * @param HTMLFormElement
 */
 function triggerChange(tableRe, table, form) {
-       var formEvent = selectValue(form['Event']);
+       const formEvent = selectValue(form['Event']);
        if (tableRe.test(form['Trigger'].value)) {
                form['Trigger'].value = table + '_' + (selectValue(form['Timing']).charAt(0) + formEvent.charAt(0)).toLowerCase();
        }
@@ -673,7 +673,7 @@ function triggerChange(tableRe, table, form) {
 
 
 
-var that, x, y; // em and tablePos defined in schema.inc.php
+let that, x, y; // em and tablePos defined in schema.inc.php
 
 /** Get mouse position
 * @param MouseEvent
@@ -692,27 +692,27 @@ function schemaMousedown(event) {
 */
 function schemaMousemove(event) {
        if (that !== undefined) {
-               var left = (event.clientX - x) / em;
-               var top = (event.clientY - y) / em;
-               var lineSet = { };
+               const left = (event.clientX - x) / em;
+               const top = (event.clientY - y) / em;
+               const lineSet = { };
                for (const div of qsa('div', that)) {
                        if (div.className == 'references') {
-                               var div2 = qs('[id="' + (/^refs/.test(div.id) ? 'refd' : 'refs') + div.id.substr(4) + '"]');
-                               var ref = (tablePos[div.title] || [ div2.parentNode.offsetTop / em, 0 ]);
-                               var left1 = -1;
-                               var id = div.id.replace(/^ref.(.+)-.+/, '$1');
+                               const div2 = qs('[id="' + (/^refs/.test(div.id) ? 'refd' : 'refs') + div.id.substr(4) + '"]');
+                               const ref = (tablePos[div.title] || [ div2.parentNode.offsetTop / em, 0 ]);
+                               let left1 = -1;
+                               const id = div.id.replace(/^ref.(.+)-.+/, '$1');
                                if (div.parentNode != div2.parentNode) {
                                        left1 = Math.min(0, ref[1] - left) - 1;
                                        div.style.left = left1 + 'em';
                                        div.querySelector('div').style.width = -left1 + 'em';
-                                       var left2 = Math.min(0, left - ref[1]) - 1;
+                                       const left2 = Math.min(0, left - ref[1]) - 1;
                                        div2.style.left = left2 + 'em';
                                        div2.querySelector('div').style.width = -left2 + 'em';
                                }
                                if (!lineSet[id]) {
-                                       var line = qs('[id="' + div.id.replace(/^....(.+)-.+$/, 'refl$1') + '"]');
-                                       var top1 = top + div.offsetTop / em;
-                                       var top2 = top + div2.offsetTop / em;
+                                       const line = qs('[id="' + div.id.replace(/^....(.+)-.+$/, 'refl$1') + '"]');
+                                       const top1 = top + div.offsetTop / em;
+                                       let top2 = top + div2.offsetTop / em;
                                        if (div.parentNode != div2.parentNode) {
                                                top2 += ref[0] - top;
                                                line.querySelector('div').style.height = Math.abs(top1 - top2) + 'em';
@@ -736,12 +736,12 @@ function schemaMouseup(event, db) {
        if (that !== undefined) {
                tablePos[that.firstChild.firstChild.firstChild.data] = [ (event.clientY - y) / em, (event.clientX - x) / em ];
                that = undefined;
-               var s = '';
-               for (var key in tablePos) {
+               let s = '';
+               for (const key in tablePos) {
                        s += '_' + key + ':' + Math.round(tablePos[key][0] * 10000) / 10000 + 'x' + Math.round(tablePos[key][1] * 10000) / 10000;
                }
                s = encodeURIComponent(s.substr(1));
-               var link = qs('#schema-link');
+               const link = qs('#schema-link');
                link.href = link.href.replace(/[^=]+$/, '') + s;
                cookie('adminer_schema-' + db + '=' + s, 30); //! special chars in db
        }
@@ -749,7 +749,7 @@ function schemaMouseup(event, db) {
 
 
 
-var helpOpen, helpIgnore; // when mouse outs <option> then it mouse overs border of <select> - ignore it
+let helpOpen, helpIgnore; // when mouse outs <option> then it mouse overs border of <select> - ignore it
 
 /** Display help
 * @param MouseEvent
@@ -758,17 +758,17 @@ var helpOpen, helpIgnore; // when mouse outs <option> then it mouse overs border
 * @this HTMLElement
 */
 function helpMouseover(event, text, side) {
-       var target = getTarget(event);
+       const target = getTarget(event);
        if (!text) {
                helpClose();
        } else if (window.jush && (!helpIgnore || this != target)) {
                helpOpen = 1;
-               var help = qs('#help');
+               const help = qs('#help');
                help.innerHTML = text;
                jush.highlight_tag([ help ]);
                alterClass(help, 'hidden');
-               var rect = target.getBoundingClientRect();
-               var body = document.documentElement;
+               const rect = target.getBoundingClientRect();
+               const body = document.documentElement;
                help.style.top = (body.scrollTop + rect.top - (side ? (help.offsetHeight - target.offsetHeight) / 2 : help.offsetHeight)) + 'px';
                help.style.left = (body.scrollLeft + rect.left - (side ? help.offsetWidth : (help.offsetWidth - target.offsetWidth) / 2)) + 'px';
        }
index 0b0451b056cef05bfc9383302de7bb4e6cbd93eb..12aa03ed655d2c20653ea603af89896eae020d92 100644 (file)
@@ -14,7 +14,7 @@ function qs(selector, context) {
 * @return HTMLElement
 */
 function qsl(selector, context) {
-       var els = qsa(selector, context);
+       const els = qsa(selector, context);
        return els[els.length - 1];
 }
 
@@ -33,7 +33,7 @@ function qsa(selector, context) {
 * @return function with preserved this
 */
 function partial(fn) {
-       var args = Array.apply(null, arguments).slice(1);
+       const args = Array.apply(null, arguments).slice(1);
        return function () {
                return fn.apply(this, args);
        };
@@ -45,7 +45,7 @@ function partial(fn) {
 * @return function with preserved this
 */
 function partialArg(fn) {
-       var args = Array.apply(null, arguments);
+       const args = Array.apply(null, arguments);
        return function (arg) {
                args[0] = arg;
                return fn.apply(this, args);
@@ -57,7 +57,7 @@ function partialArg(fn) {
 * @param Object
 */
 function mixin(target, source) {
-       for (var key in source) {
+       for (const key in source) {
                target[key] = source[key];
        }
 }
@@ -78,7 +78,7 @@ function alterClass(el, className, enable) {
 * @return boolean false
 */
 function toggle(id) {
-       var el = qs('#' + id);
+       const el = qs('#' + id);
        alterClass(el, 'hidden', !/(^|\s)hidden(\s|$)/.test(el.className));
        return false;
 }
@@ -88,7 +88,7 @@ function toggle(id) {
 * @param number
 */
 function cookie(assign, days) {
-       var date = new Date();
+       const date = new Date();
        date.setDate(date.getDate() + days);
        document.cookie = assign + '; expires=' + date;
 }
@@ -100,7 +100,7 @@ function cookie(assign, days) {
 */
 function verifyVersion(current, url, token) {
        cookie('adminer_version=0', 1);
-       var iframe = document.createElement('iframe');
+       const iframe = document.createElement('iframe');
        iframe.src = 'https://www.adminer.org/version/?current=' + current;
        iframe.frameBorder = 0;
        iframe.marginHeight = 0;
@@ -110,7 +110,7 @@ function verifyVersion(current, url, token) {
        iframe.style.display = 'none';
        addEventListener('message', function (event) {
                if (event.origin == 'https://www.adminer.org') {
-                       var match = /version=(.+)/.exec(event.data);
+                       const match = /version=(.+)/.exec(event.data);
                        if (match) {
                                cookie('adminer_version=' + match[1], 1);
                                ajax(url + 'script=version', function () {
@@ -129,7 +129,7 @@ function selectValue(select) {
        if (!select.selectedIndex) {
                return select.value;
        }
-       var selected = select.options[select.selectedIndex];
+       const selected = select.options[select.selectedIndex];
        return ((selected.attributes.value || {}).specified ? selected.value : selected.text);
 }
 
@@ -139,7 +139,7 @@ function selectValue(select) {
 * @return boolean
 */
 function isTag(el, tag) {
-       var re = new RegExp('^(' + tag + ')$', 'i');
+       const re = new RegExp('^(' + tag + ')$', 'i');
        return el && re.test(el.tagName);
 }
 
@@ -159,7 +159,7 @@ function parentTag(el, tag) {
 * @param HTMLInputElement
 */
 function trCheck(el) {
-       var tr = parentTag(el, 'tr');
+       const tr = parentTag(el, 'tr');
        alterClass(tr, 'checked', el.checked);
        if (el.form && el.form['all'] && el.form['all'].onclick) { // Opera treats form.all as document.all
                el.form['all'].onclick();
@@ -173,7 +173,7 @@ function trCheck(el) {
 */
 function selectCount(id, count) {
        setHtml(id, (count === '' ? '' : '(' + (count + '').replace(/\B(?=(\d{3})+$)/g, thousandsSeparator) + ')'));
-       var el = qs('#' + id);
+       const el = qs('#' + id);
        if (el) {
                for (const input of qsa('input', el.parentNode.parentNode)) {
                        if (input.type == 'submit') {
@@ -208,7 +208,7 @@ function tableCheck() {
 * @param string
 */
 function formUncheck(id) {
-       var el = qs('#' + id);
+       const el = qs('#' + id);
        el.checked = false;
        trCheck(el);
 }
@@ -219,7 +219,7 @@ function formUncheck(id) {
 * @return number
 */
 function formChecked(input, name) {
-       var checked = 0;
+       let checked = 0;
        for (const el of input.form.elements) {
                if (name.test(el.name) && el.checked) {
                        checked++;
@@ -233,15 +233,15 @@ function formChecked(input, name) {
 * @param [boolean] force click
 */
 function tableClick(event, click) {
-       var td = parentTag(getTarget(event), 'td');
-       var text;
+       const td = parentTag(getTarget(event), 'td');
+       let text;
        if (td && (text = td.getAttribute('data-text'))) {
                if (selectClick.call(td, event, +text, td.getAttribute('data-warning'))) {
                        return;
                }
        }
        click = (click || !window.getSelection || getSelection().isCollapsed);
-       var el = getTarget(event);
+       let el = getTarget(event);
        while (!isTag(el, 'tr')) {
                if (isTag(el, 'table|a|input|textarea')) {
                        if (el.type != 'checkbox') {
@@ -270,7 +270,7 @@ function tableClick(event, click) {
        trCheck(el);
 }
 
-var lastChecked;
+let lastChecked;
 
 /** Shift-click on checkbox for multiple selection.
 * @param MouseEvent
@@ -281,8 +281,8 @@ function checkboxClick(event) {
                return;
        }
        if (event.shiftKey && (!lastChecked || lastChecked.name == this.name)) {
-               var checked = (lastChecked ? lastChecked.checked : true);
-               var checking = !lastChecked;
+               const checked = (lastChecked ? lastChecked.checked : true);
+               let checking = !lastChecked;
                for (const input of qsa('input', parentTag(this, 'table'))) {
                        if (input.name === this.name) {
                                if (checking) {
@@ -307,7 +307,7 @@ function checkboxClick(event) {
 * @param string undefined to set parentNode to empty string
 */
 function setHtml(id, html) {
-       var el = qs('[id="' + id.replace(/[\\"]/g, '\\$&') + '"]'); // database name is used as ID
+       const el = qs('[id="' + id.replace(/[\\"]/g, '\\$&') + '"]'); // database name is used as ID
        if (el) {
                if (html == null) {
                        el.parentNode.innerHTML = '';
@@ -322,7 +322,7 @@ function setHtml(id, html) {
 * @return number
 */
 function nodePosition(el) {
-       var pos = 0;
+       let pos = 0;
        while ((el = el.previousSibling)) {
                pos++;
        }
@@ -346,7 +346,7 @@ function pageClick(href, page) {
 * @this HTMLElement
 */
 function menuOver(event) {
-       var a = getTarget(event);
+       const a = getTarget(event);
        if (isTag(a, 'a|span') && a.offsetLeft + a.offsetWidth > a.parentNode.offsetWidth - 15) { // 15 - ellipsis
                this.style.overflow = 'visible';
        }
@@ -365,8 +365,8 @@ function menuOut() {
 * @this HTMLSelectElement
 */
 function selectAddRow() {
-       var field = this;
-       var row = cloneNode(field.parentNode);
+       const field = this;
+       const row = cloneNode(field.parentNode);
        field.onchange = selectFieldChange;
        field.onchange();
        for (const select of qsa('select', row)) {
@@ -426,12 +426,12 @@ function columnMouse(className) {
 * @return boolean false
 */
 function selectSearch(name) {
-       var el = qs('#fieldset-search');
+       let el = qs('#fieldset-search');
        el.className = '';
-       var divs = qsa('div', el);
-       var i;
+       const divs = qsa('div', el);
+       let i, div;
        for (i=0; i < divs.length; i++) {
-               var div = divs[i];
+               div = divs[i];
                el = qs('[name$="[col]"]', div);
                if (el && selectValue(el) == name) {
                        break;
@@ -471,7 +471,7 @@ function getTarget(event) {
 */
 function bodyKeydown(event, button) {
        eventStop(event);
-       var target = getTarget(event);
+       let target = getTarget(event);
        if (target.jushTextarea) {
                target = target.jushTextarea;
        }
@@ -495,7 +495,7 @@ function bodyKeydown(event, button) {
 * @param MouseEvent
 */
 function bodyClick(event) {
-       var target = getTarget(event);
+       const target = getTarget(event);
        if ((isCtrl(event) || event.shiftKey) && target.type == 'submit' && isTag(target, 'input')) {
                target.form.target = '_blank';
                setTimeout(function () {
@@ -513,9 +513,9 @@ function bodyClick(event) {
 */
 function editingKeydown(event) {
        if ((event.keyCode == 40 || event.keyCode == 38) && isCtrl(event)) { // 40 - Down, 38 - Up
-               var target = getTarget(event);
-               var sibling = (event.keyCode == 40 ? 'nextSibling' : 'previousSibling');
-               var el = target.parentNode.parentNode[sibling];
+               const target = getTarget(event);
+               const sibling = (event.keyCode == 40 ? 'nextSibling' : 'previousSibling');
+               let el = target.parentNode.parentNode[sibling];
                if (el && (isTag(el, 'tr') || (el = el[sibling])) && isTag(el, 'tr') && (el = el.childNodes[nodePosition(target.parentNode)]) && (el = el.childNodes[nodePosition(target)])) {
                        el.focus();
                }
@@ -531,7 +531,7 @@ function editingKeydown(event) {
 * @this HTMLSelectElement
 */
 function functionChange() {
-       var input = this.form[this.name.replace(/^function/, 'fields')];
+       const input = this.form[this.name.replace(/^function/, 'fields')];
        if (input) { // undefined with the set data type
                if (selectValue(this)) {
                        if (input.origType === undefined) {
@@ -556,7 +556,7 @@ function functionChange() {
 * @this HTMLTableCellElement
 */
 function skipOriginal(first) {
-       var fnSelect = qs('select', this.previousSibling);
+       const fnSelect = qs('select', this.previousSibling);
        if (fnSelect.selectedIndex < first) {
                fnSelect.selectedIndex = first;
        }
@@ -566,7 +566,7 @@ function skipOriginal(first) {
 * @this HTMLInputElement
 */
 function fieldChange() {
-       var row = cloneNode(parentTag(this, 'tr'));
+       const row = cloneNode(parentTag(this, 'tr'));
        for (const input of qsa('input', row)) {
                input.value = '';
        }
@@ -586,9 +586,9 @@ function fieldChange() {
 * @uses offlineMessage
 */
 function ajax(url, callback, data, message) {
-       var request = new XMLHttpRequest();
+       const request = new XMLHttpRequest();
        if (request) {
-               var ajaxStatus = qs('#ajaxstatus');
+               const ajaxStatus = qs('#ajaxstatus');
                if (message) {
                        ajaxStatus.innerHTML = '<div class="message">' + message + '</div>';
                        ajaxStatus.className = ajaxStatus.className.replace(/ hidden/g, '');
@@ -621,8 +621,8 @@ function ajax(url, callback, data, message) {
 */
 function ajaxSetHtml(url) {
        return !ajax(url, function (request) {
-               var data = JSON.parse(request.responseText);
-               for (var key in data) {
+               const data = JSON.parse(request.responseText);
+               for (const key in data) {
                        setHtml(key, data[key]);
                }
        });
@@ -635,7 +635,7 @@ function ajaxSetHtml(url) {
 * @return boolean
 */
 function ajaxForm(form, message, button) {
-       var data = [];
+       let data = [];
        for (const el of form.elements) {
                if (el.name && !el.disabled) {
                        if (/^file$/i.test(el.type) && el.value) {
@@ -648,7 +648,7 @@ function ajaxForm(form, message, button) {
        }
        data = data.join('&');
 
-       var url = form.action;
+       let url = form.action;
        if (!/post/i.test(form.method)) {
                url = url.replace(/\?.*/, '') + '?' + data;
                data = '';
@@ -672,8 +672,8 @@ function ajaxForm(form, message, button) {
 * @this HTMLElement
 */
 function selectClick(event, text, warning) {
-       var td = this;
-       var target = getTarget(event);
+       const td = this;
+       const target = getTarget(event);
        if (!isCtrl(event) || isTag(td.firstChild, 'input|textarea') || isTag(target, 'a')) {
                return;
        }
@@ -681,9 +681,9 @@ function selectClick(event, text, warning) {
                alert(warning);
                return true;
        }
-       var original = td.innerHTML;
+       const original = td.innerHTML;
        text = text || /\n/.test(original);
-       var input = document.createElement(text ? 'textarea' : 'input');
+       const input = document.createElement(text ? 'textarea' : 'input');
        input.onkeydown = function (event) {
                if (!event) {
                        event = window.event;
@@ -701,7 +701,7 @@ function selectClick(event, text, warning) {
        input.style.width = Math.max(td.clientWidth - parseFloat(tdStyle.paddingLeft) - parseFloat(tdStyle.paddingRight), 20) + 'px';
 
        if (text) {
-               var rows = 1;
+               let rows = 1;
                value.replace(/\n/g, function () {
                        rows++;
                });
@@ -711,9 +711,9 @@ function selectClick(event, text, warning) {
                value = '';
        }
        if (document.selection) {
-               var range = document.selection.createRange();
+               const range = document.selection.createRange();
                range.moveToPoint(event.clientX, event.clientY);
-               var range2 = range.duplicate();
+               const range2 = range.duplicate();
                range2.moveToElementText(td);
                range2.setEndPoint('EndToEnd', range);
                pos = range2.text.length;
@@ -735,7 +735,7 @@ function selectClick(event, text, warning) {
        input.selectionStart = pos;
        input.selectionEnd = pos;
        if (document.selection) {
-               var range = document.selection.createRange();
+               const range = document.selection.createRange();
                range.moveEnd('character', -input.value.length + pos);
                range.select();
        }
@@ -751,14 +751,14 @@ function selectClick(event, text, warning) {
 * @this HTMLLinkElement
 */
 function selectLoadMore(limit, loading) {
-       var a = this;
-       var title = a.innerHTML;
-       var href = a.href;
+       const a = this;
+       const title = a.innerHTML;
+       const href = a.href;
        a.innerHTML = loading;
        if (href) {
                a.removeAttribute('href');
                return !ajax(href, function (request) {
-                       var tbody = document.createElement('tbody');
+                       const tbody = document.createElement('tbody');
                        tbody.innerHTML = request.responseText;
                        qs('#table').appendChild(tbody);
                        if (tbody.children.length < limit) {
@@ -792,7 +792,7 @@ function eventStop(event) {
 * @param HTMLElement
 */
 function setupSubmitHighlight(parent) {
-       for (var key in { input: 1, select: 1, textarea: 1 }) {
+       for (const key in { input: 1, select: 1, textarea: 1 }) {
                for (const input of qsa(key, parent)) {
                        setupSubmitHighlightInput(input);
                }
@@ -813,7 +813,7 @@ function setupSubmitHighlightInput(input) {
 * @this HTMLInputElement
 */
 function inputFocus() {
-       var submit = findDefaultSubmit(this);
+       const submit = findDefaultSubmit(this);
        if (submit) {
                alterClass(submit, 'default', true);
        }
@@ -823,7 +823,7 @@ function inputFocus() {
 * @this HTMLInputElement
 */
 function inputBlur() {
-       var submit = findDefaultSubmit(this);
+       const submit = findDefaultSubmit(this);
        if (submit) {
                alterClass(submit, 'default');
        }
@@ -867,13 +867,13 @@ function addEvent(el, action, handler) {
 * @return HTMLElement
 */
 function cloneNode(el) {
-       var el2 = el.cloneNode(true);
-       var selector = 'input, select';
-       var origEls = qsa(selector, el);
-       var cloneEls = qsa(selector, el2);
-       for (var i=0; i < origEls.length; i++) {
-               var origEl = origEls[i];
-               for (var key in origEl) {
+       const el2 = el.cloneNode(true);
+       const selector = 'input, select';
+       const origEls = qsa(selector, el);
+       const cloneEls = qsa(selector, el2);
+       for (let i=0; i < origEls.length; i++) {
+               const origEl = origEls[i];
+               for (const key in origEl) {
                        if (/^on/.test(key) && origEl[key]) {
                                cloneEls[i][key] = origEl[key];
                        }
@@ -884,7 +884,7 @@ function cloneNode(el) {
 }
 
 oninput = function (event) {
-       var target = event.target;
-       var maxLength = target.getAttribute('data-maxlength');
+       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 fe511b7ffc523e0f7ac2695b125f9a056cce1f68..531e56d453ddd8a24f097619d2b49512f4f70a36 100644 (file)
@@ -6,7 +6,7 @@ function messagesPrint() {
 function selectFieldChange() {
 }
 
-var helpOpen;
+let helpOpen;
 
 function helpMouseover() {
 }
@@ -22,14 +22,14 @@ function helpClose() {
 * @this HTMLInputElement
 */
 function whisper(url) {
-       var field = this;
+       const field = this;
        field.orig = field.value;
        field.previousSibling.value = field.value; // accept number, reject string
        return ajax(url + encodeURIComponent(field.value), function (xmlhttp) {
                if (xmlhttp.status && field.orig == field.value) { // ignore old responses
                        field.nextSibling.innerHTML = xmlhttp.responseText;
                        field.nextSibling.style.display = '';
-                       var a = field.nextSibling.firstChild;
+                       const a = field.nextSibling.firstChild;
                        if (a && a.firstChild.data == field.value) {
                                field.previousSibling.value = decodeURIComponent(a.href.replace(/.*=/, ''));
                                a.className = 'active';
@@ -44,8 +44,8 @@ function whisper(url) {
 * @this HTMLDivElement
 */
 function whisperClick(event) {
-       var field = this.previousSibling;
-       var el = getTarget(event);
+       const field = this.previousSibling;
+       const el = getTarget(event);
        if (isTag(el, 'a') && !(event.button || event.shiftKey || event.altKey || isCtrl(event))) {
                field.value = el.firstChild.data;
                field.previousSibling.value = decodeURIComponent(el.href.replace(/.*=/, ''));
@@ -58,7 +58,7 @@ function whisperClick(event) {
 * @this HTMLInputElement
 */
 function emailFileChange() {
-       var el = this.cloneNode(true);
+       const el = this.cloneNode(true);
        this.onchange = function () { };
        el.value = '';
        this.parentNode.appendChild(el);