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')
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);
}
*/
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];
}
* @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
* @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) {
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;
}
}
}
if (group) {
- for (var col in columns) {
+ for (const col in columns) {
if (!(col in indexColumns)) {
ok = false;
}
-var added = '.', rowCount;
+let added = '.', rowCount;
/** Check if val is equal to a-delimiter-b where delimiter is '_', '' or big letter
* @param string
* @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)) {
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();
* @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);
* @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) {
* @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;
* @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;
* @this HTMLInputElement
*/
function editingMoveRow(up){
- var row = parentTag(this, 'tr');
+ const row = parentTag(this, 'tr');
if (!('nextElementSibling' in row)) {
return true;
}
* @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 (!(
* @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';
* @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;
* @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';
* @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();
* @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 () {};
* @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) {
* @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]);
* @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$&');
* @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');
* @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);
}
* @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;
* @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();
}
-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
*/
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';
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
}
-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
* @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';
}
* @return HTMLElement
*/
function qsl(selector, context) {
- var els = qsa(selector, context);
+ const els = qsa(selector, context);
return els[els.length - 1];
}
* @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);
};
* @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);
* @param Object
*/
function mixin(target, source) {
- for (var key in source) {
+ for (const key in source) {
target[key] = source[key];
}
}
* @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;
}
* @param number
*/
function cookie(assign, days) {
- var date = new Date();
+ const date = new Date();
date.setDate(date.getDate() + days);
document.cookie = assign + '; expires=' + date;
}
*/
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;
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 () {
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);
}
* @return boolean
*/
function isTag(el, tag) {
- var re = new RegExp('^(' + tag + ')$', 'i');
+ const re = new RegExp('^(' + tag + ')$', 'i');
return el && re.test(el.tagName);
}
* @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();
*/
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') {
* @param string
*/
function formUncheck(id) {
- var el = qs('#' + id);
+ const el = qs('#' + id);
el.checked = false;
trCheck(el);
}
* @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++;
* @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') {
trCheck(el);
}
-var lastChecked;
+let lastChecked;
/** Shift-click on checkbox for multiple selection.
* @param MouseEvent
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) {
* @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 = '';
* @return number
*/
function nodePosition(el) {
- var pos = 0;
+ let pos = 0;
while ((el = el.previousSibling)) {
pos++;
}
* @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';
}
* @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)) {
* @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;
*/
function bodyKeydown(event, button) {
eventStop(event);
- var target = getTarget(event);
+ let target = getTarget(event);
if (target.jushTextarea) {
target = target.jushTextarea;
}
* @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 () {
*/
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();
}
* @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) {
* @this HTMLTableCellElement
*/
function skipOriginal(first) {
- var fnSelect = qs('select', this.previousSibling);
+ const fnSelect = qs('select', this.previousSibling);
if (fnSelect.selectedIndex < first) {
fnSelect.selectedIndex = 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 = '';
}
* @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, '');
*/
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]);
}
});
* @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) {
}
data = data.join('&');
- var url = form.action;
+ let url = form.action;
if (!/post/i.test(form.method)) {
url = url.replace(/\?.*/, '') + '?' + data;
data = '';
* @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;
}
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;
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++;
});
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;
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();
}
* @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) {
* @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);
}
* @this HTMLInputElement
*/
function inputFocus() {
- var submit = findDefaultSubmit(this);
+ const submit = findDefaultSubmit(this);
if (submit) {
alterClass(submit, 'default', true);
}
* @this HTMLInputElement
*/
function inputBlur() {
- var submit = findDefaultSubmit(this);
+ const submit = findDefaultSubmit(this);
if (submit) {
alterClass(submit, 'default');
}
* @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];
}
}
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
};