Replace getElementById by shortcut for querySelector (requires IE8)
This commit is contained in:
parent
67f6aea77f
commit
9cb281868f
13 changed files with 43 additions and 35 deletions
|
@ -163,7 +163,7 @@ foreach ($engines as $engine) {
|
|||
<p>
|
||||
<?php if (support("columns") || $TABLE == "") { ?>
|
||||
<?php echo lang('Table name'); ?>: <input name="name" maxlength="64" value="<?php echo h($row["name"]); ?>" autocapitalize="off">
|
||||
<?php if ($TABLE == "" && !$_POST) { ?><script type='text/javascript'>focus(document.getElementById('form')['name']);</script><?php } ?>
|
||||
<?php if ($TABLE == "" && !$_POST) { ?><script type='text/javascript'>focus(qs('#form')['name']);</script><?php } ?>
|
||||
<?php echo ($engines ? "<select name='Engine' onchange='helpClose();'" . on_help("getTarget(event).value", 1) . ">" . optionlist(array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]) . "</select>" : ""); ?>
|
||||
<?php echo ($collations && !preg_match("~sqlite|mssql~", $jush) ? html_select("Collation", array("" => "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?>
|
||||
<input type="submit" value="<?php echo lang('Save'); ?>">
|
||||
|
|
|
@ -66,7 +66,7 @@ echo ($_POST["add_x"] || strpos($name, "\n")
|
|||
'mssql' => "ms187963.aspx",
|
||||
)) : "");
|
||||
?>
|
||||
<script type='text/javascript'>focus(document.getElementById('name'));</script>
|
||||
<script type='text/javascript'>focus(qs('#name'));</script>
|
||||
<input type="submit" value="<?php echo lang('Save'); ?>">
|
||||
<?php
|
||||
if (DB != "") {
|
||||
|
|
|
@ -95,7 +95,7 @@ class Adminer {
|
|||
<tr><th><?php echo lang('Database'); ?><td><input name="auth[db]" value="<?php echo h($_GET["db"]); ?>" autocapitalize="off">
|
||||
</table>
|
||||
<script type="text/javascript">
|
||||
focus(document.getElementById('username'));
|
||||
focus(qs('#username'));
|
||||
</script>
|
||||
<?php
|
||||
echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
|
||||
|
@ -413,7 +413,7 @@ focus(document.getElementById('username'));
|
|||
json_row($key);
|
||||
}
|
||||
echo ";\n";
|
||||
echo "selectFieldChange(document.getElementById('form'));\n";
|
||||
echo "selectFieldChange(qs('#form'));\n";
|
||||
echo "</script>\n";
|
||||
echo "</div></fieldset>\n";
|
||||
}
|
||||
|
|
|
@ -1383,7 +1383,7 @@ function edit_form($TABLE, $fields, $row, $update) {
|
|||
}
|
||||
}
|
||||
echo ($update ? "<input type='submit' name='delete' value='" . lang('Delete') . "'" . confirm() . ">\n"
|
||||
: ($_POST || !$fields ? "" : "<script type='text/javascript'>focus(document.getElementById('form').getElementsByTagName('td')[1].firstChild);</script>\n")
|
||||
: ($_POST || !$fields ? "" : "<script type='text/javascript'>focus(qs('#form').getElementsByTagName('td')[1].firstChild);</script>\n")
|
||||
);
|
||||
if (isset($_GET["select"])) {
|
||||
hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
|
||||
|
|
|
@ -51,7 +51,7 @@ foreach (table_status('', true) as $table => $table_status) {
|
|||
<div id="schema" style="height: <?php echo $top; ?>em;" onselectstart="return false;">
|
||||
<script type="text/javascript">
|
||||
var tablePos = {<?php echo implode(",", $table_pos_js) . "\n"; ?>};
|
||||
var em = document.getElementById('schema').offsetHeight / <?php echo $top; ?>;
|
||||
var em = qs('#schema').offsetHeight / <?php echo $top; ?>;
|
||||
document.onmousemove = schemaMousemove;
|
||||
document.onmouseup = function (ev) {
|
||||
schemaMouseup(ev, '<?php echo js_escape(DB); ?>');
|
||||
|
|
|
@ -27,7 +27,7 @@ if (!$row) {
|
|||
|
||||
<form action="" method="post">
|
||||
<p><input name="name" id="name" value="<?php echo h($row["name"]); ?>" autocapitalize="off">
|
||||
<script type='text/javascript'>focus(document.getElementById('name'));</script>
|
||||
<script type='text/javascript'>focus(qs('#name'));</script>
|
||||
<input type="submit" value="<?php echo lang('Save'); ?>">
|
||||
<?php
|
||||
if ($_GET["ns"] != "") {
|
||||
|
|
|
@ -338,7 +338,7 @@ function editingLengthChange(el) {
|
|||
function editingLengthFocus(field) {
|
||||
var td = field.parentNode;
|
||||
if (/(enum|set)$/.test(selectValue(td.previousSibling.firstChild))) {
|
||||
var edit = document.getElementById('enum-edit');
|
||||
var edit = qs('#enum-edit');
|
||||
var val = field.value;
|
||||
edit.value = (/^'.+'$/.test(val) ? val.substr(1, val.length - 2).replace(/','/g, "\n").replace(/''/g, "'") : val); //! doesn't handle 'a'',''b' correctly
|
||||
td.appendChild(edit);
|
||||
|
@ -364,7 +364,7 @@ function editingLengthBlur(edit) {
|
|||
* @param number
|
||||
*/
|
||||
function columnShow(checked, column) {
|
||||
var trs = document.getElementById('edit-fields').getElementsByTagName('tr');
|
||||
var trs = qs('#edit-fields').getElementsByTagName('tr');
|
||||
for (var i=0; i < trs.length; i++) {
|
||||
alterClass(trs[i].getElementsByTagName('td')[column], 'hidden', !checked);
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ function columnShow(checked, column) {
|
|||
*/
|
||||
function editingHideDefaults() {
|
||||
if (innerWidth < document.documentElement.scrollWidth) {
|
||||
document.getElementById('form')['defaults'].checked = false;
|
||||
qs('#form')['defaults'].checked = false;
|
||||
columnShow(false, 5);
|
||||
}
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ function editingHideDefaults() {
|
|||
function partitionByChange(el) {
|
||||
var partitionTable = /RANGE|LIST/.test(selectValue(el));
|
||||
alterClass(el.form['partitions'], 'hidden', partitionTable || !el.selectedIndex);
|
||||
alterClass(document.getElementById('partition-table'), 'hidden', !partitionTable);
|
||||
alterClass(qs('#partition-table'), 'hidden', !partitionTable);
|
||||
helpClose();
|
||||
}
|
||||
|
||||
|
@ -533,7 +533,7 @@ function schemaMousemove(ev) {
|
|||
var lineSet = { };
|
||||
for (var i=0; i < divs.length; i++) {
|
||||
if (divs[i].className == 'references') {
|
||||
var div2 = document.getElementById((/^refs/.test(divs[i].id) ? 'refd' : 'refs') + divs[i].id.substr(4));
|
||||
var div2 = qs('#' + (/^refs/.test(divs[i].id) ? 'refd' : 'refs') + divs[i].id.substr(4));
|
||||
var ref = (tablePos[divs[i].title] ? tablePos[divs[i].title] : [ div2.parentNode.offsetTop / em, 0 ]);
|
||||
var left1 = -1;
|
||||
var id = divs[i].id.replace(/^ref.(.+)-.+/, '$1');
|
||||
|
@ -546,7 +546,7 @@ function schemaMousemove(ev) {
|
|||
div2.getElementsByTagName('div')[0].style.width = -left2 + 'em';
|
||||
}
|
||||
if (!lineSet[id]) {
|
||||
var line = document.getElementById(divs[i].id.replace(/^....(.+)-.+$/, 'refl$1'));
|
||||
var line = qs('#' + divs[i].id.replace(/^....(.+)-.+$/, 'refl$1'));
|
||||
var top1 = top + divs[i].offsetTop / em;
|
||||
var top2 = top + div2.offsetTop / em;
|
||||
if (divs[i].parentNode != div2.parentNode) {
|
||||
|
@ -578,7 +578,7 @@ function schemaMouseup(ev, db) {
|
|||
s += '_' + key + ':' + Math.round(tablePos[key][0] * 10000) / 10000 + 'x' + Math.round(tablePos[key][1] * 10000) / 10000;
|
||||
}
|
||||
s = encodeURIComponent(s.substr(1));
|
||||
var link = document.getElementById('schema-link');
|
||||
var link = qs('#schema-link');
|
||||
link.href = link.href.replace(/[^=]+$/, '') + s;
|
||||
cookie('adminer_schema-' + db + '=' + s, 30); //! special chars in db
|
||||
}
|
||||
|
@ -600,7 +600,7 @@ function helpMouseover(el, event, text, side) {
|
|||
helpClose();
|
||||
} else if (window.jush && (!helpIgnore || el != target)) {
|
||||
helpOpen = 1;
|
||||
var help = document.getElementById('help');
|
||||
var help = qs('#help');
|
||||
help.innerHTML = text;
|
||||
jush.highlight_tag([ help ]);
|
||||
alterClass(help, 'hidden');
|
||||
|
@ -628,5 +628,5 @@ function helpMouseout(el, event) {
|
|||
/** Close help
|
||||
*/
|
||||
function helpClose() {
|
||||
alterClass(document.getElementById('help'), 'hidden', true);
|
||||
alterClass(qs('#help'), 'hidden', true);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
|
||||
/** Get first element by selector
|
||||
* @param string
|
||||
* @return HTMLElement
|
||||
*/
|
||||
function qs(selector) {
|
||||
return document.querySelector(selector);
|
||||
}
|
||||
|
||||
/** Add or remove CSS class
|
||||
* @param HTMLElement
|
||||
* @param string
|
||||
|
@ -15,7 +23,7 @@ function alterClass(el, className, enable) {
|
|||
* @return boolean
|
||||
*/
|
||||
function toggle(id) {
|
||||
var el = document.getElementById(id);
|
||||
var el = qs('#' + id);
|
||||
el.className = (el.className == 'hidden' ? '' : 'hidden');
|
||||
return true;
|
||||
}
|
||||
|
@ -54,7 +62,7 @@ function verifyVersion(current) {
|
|||
}
|
||||
}, false);
|
||||
}
|
||||
document.getElementById('version').appendChild(iframe);
|
||||
qs('#version').appendChild(iframe);
|
||||
}
|
||||
|
||||
/** Get value of select
|
||||
|
@ -108,7 +116,7 @@ function trCheck(el) {
|
|||
*/
|
||||
function selectCount(id, count) {
|
||||
setHtml(id, (count === '' ? '' : '(' + (count + '').replace(/\B(?=(\d{3})+$)/g, ' ') + ')'));
|
||||
var inputs = document.getElementById(id).parentNode.parentNode.getElementsByTagName('input');
|
||||
var inputs = qs('#' + id).parentNode.parentNode.getElementsByTagName('input');
|
||||
for (var i = 0; i < inputs.length; i++) {
|
||||
var input = inputs[i];
|
||||
if (input.type == 'submit') {
|
||||
|
@ -149,7 +157,7 @@ function tableCheck() {
|
|||
* @param string
|
||||
*/
|
||||
function formUncheck(id) {
|
||||
var el = document.getElementById(id);
|
||||
var el = qs('#' + id);
|
||||
el.checked = false;
|
||||
trCheck(el);
|
||||
}
|
||||
|
@ -237,7 +245,7 @@ function checkboxClick(event, el) {
|
|||
* @param string undefined to set parentNode to
|
||||
*/
|
||||
function setHtml(id, html) {
|
||||
var el = document.getElementById(id);
|
||||
var el = qs('#' + id);
|
||||
if (el) {
|
||||
if (html == null) {
|
||||
el.parentNode.innerHTML = ' ';
|
||||
|
@ -361,7 +369,7 @@ function columnMouse(el, className) {
|
|||
* @param string
|
||||
*/
|
||||
function selectSearch(name) {
|
||||
var el = document.getElementById('fieldset-search');
|
||||
var el = qs('#fieldset-search');
|
||||
el.className = '';
|
||||
var divs = el.getElementsByTagName('div');
|
||||
for (var i=0; i < divs.length; i++) {
|
||||
|
@ -514,7 +522,7 @@ function fieldChange(field) {
|
|||
function ajax(url, callback, data, message) {
|
||||
var request = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : false));
|
||||
if (request) {
|
||||
var ajaxStatus = document.getElementById('ajaxstatus');
|
||||
var ajaxStatus = qs('#ajaxstatus');
|
||||
if (message) {
|
||||
ajaxStatus.innerHTML = '<div class="message">' + message + '</div>';
|
||||
ajaxStatus.className = ajaxStatus.className.replace(/ hidden/g, '');
|
||||
|
@ -584,7 +592,7 @@ function ajaxForm(form, message, button) {
|
|||
return ajax(url, function (request) {
|
||||
setHtml('ajaxstatus', request.responseText);
|
||||
if (window.jush) {
|
||||
jush.highlight_tag(document.getElementById('ajaxstatus').getElementsByTagName('code'), 0);
|
||||
jush.highlight_tag(qs('#ajaxstatus').getElementsByTagName('code'), 0);
|
||||
}
|
||||
}, data, message);
|
||||
}
|
||||
|
@ -678,7 +686,7 @@ function selectLoadMore(a, limit, loading) {
|
|||
return ajax(href, function (request) {
|
||||
var tbody = document.createElement('tbody');
|
||||
tbody.innerHTML = request.responseText;
|
||||
document.getElementById('table').appendChild(tbody);
|
||||
qs('#table').appendChild(tbody);
|
||||
if (tbody.children.length < limit) {
|
||||
a.parentNode.removeChild(a);
|
||||
} else {
|
||||
|
|
|
@ -40,7 +40,7 @@ page_header(($name != "" ? lang('Alter trigger') . ": " . h($name) : lang('Creat
|
|||
<tr><th><?php echo lang('Type'); ?><td><?php echo html_select("Type", $trigger_options["Type"], $row["Type"]); ?>
|
||||
</table>
|
||||
<p><?php echo lang('Name'); ?>: <input name="Trigger" value="<?php echo h($row["Trigger"]); ?>" maxlength="64" autocapitalize="off">
|
||||
<script type="text/javascript">document.getElementById('form')['Timing'].onchange();</script>
|
||||
<script type="text/javascript">qs('#form')['Timing'].onchange();</script>
|
||||
<p><?php textarea("Statement", $row["Statement"]); ?>
|
||||
<p>
|
||||
<input type="submit" value="<?php echo lang('Save'); ?>">
|
||||
|
|
|
@ -135,7 +135,7 @@ if ($_POST) {
|
|||
<tr><th><?php echo lang('Server'); ?><td><input name="host" maxlength="60" value="<?php echo h($row["host"]); ?>" autocapitalize="off">
|
||||
<tr><th><?php echo lang('Username'); ?><td><input name="user" maxlength="16" value="<?php echo h($row["user"]); ?>" autocapitalize="off">
|
||||
<tr><th><?php echo lang('Password'); ?><td><input name="pass" id="pass" value="<?php echo h($row["pass"]); ?>">
|
||||
<?php if (!$row["hashed"]) { ?><script type="text/javascript">typePassword(document.getElementById('pass'));</script><?php } ?>
|
||||
<?php if (!$row["hashed"]) { ?><script type="text/javascript">typePassword(qs('#pass'));</script><?php } ?>
|
||||
<?php echo checkbox("hashed", 1, $row["hashed"], lang('Hashed'), "typePassword(this.form['pass'], this.checked);"); ?>
|
||||
</table>
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ class Adminer {
|
|||
<tr><th><?php echo lang('Password'); ?><td><input type="password" name="auth[password]">
|
||||
</table>
|
||||
<script type="text/javascript">
|
||||
focus(document.getElementById('username'));
|
||||
focus(qs('#username'));
|
||||
</script>
|
||||
<?php
|
||||
echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
|
||||
|
@ -399,7 +399,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
|
|||
$field = idf_escape($_POST["email_field"]);
|
||||
$subject = $_POST["email_subject"];
|
||||
$message = $_POST["email_message"];
|
||||
preg_match_all('~\\{\\$([a-z0-9_]+)\\}~i', "$subject.$message", $matches); // allows {$name} in subject or message
|
||||
preg_match_all('~\\{\\$('#' + [a-z0-9_]+)\\}~i', "$subject.$message", $matches); // allows {$name} in subject or message
|
||||
$rows = get_rows("SELECT DISTINCT $field" . ($matches[1] ? ", " . implode(", ", array_map('idf_escape', array_unique($matches[1]))) : "") . " FROM " . table($_GET["select"])
|
||||
. " WHERE $field IS NOT NULL AND $field != ''"
|
||||
. ($where ? " AND " . implode(" AND ", $where) : "")
|
||||
|
@ -488,7 +488,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
|
|||
return "$function()";
|
||||
}
|
||||
$return = $value;
|
||||
if (preg_match('~date|timestamp~', $field["type"]) && preg_match('(^' . str_replace('\\$1', '(?P<p1>\\d*)', preg_replace('~(\\\\\\$([2-6]))~', '(?P<p\\2>\\d{1,2})', preg_quote(lang('$1-$3-$5')))) . '(.*))', $value, $match)) {
|
||||
if (preg_match('~date|timestamp~', $field["type"]) && preg_match('(^' . str_replace('\\$1', '(?P<p1>\\d*)', preg_replace('~(\\\\\\$('#' + [2-6]))~', '(?P<p\\2>\\d{1,2})', preg_quote(lang('$1-$3-$5')))) . '(.*))', $value, $match)) {
|
||||
$return = ($match["p1"] != "" ? $match["p1"] : ($match["p2"] != "" ? ($match["p2"] < 70 ? 20 : 19) . $match["p2"] : gmdate("Y"))) . "-$match[p3]$match[p4]-$match[p5]$match[p6]" . end($match);
|
||||
}
|
||||
$return = ($field["type"] == "bit" && preg_match('~^[0-9]+$~', $value) ? $return : q($return));
|
||||
|
|
|
@ -28,7 +28,7 @@ var tablesFilterTimeout = null;
|
|||
var tablesFilterValue = '';
|
||||
|
||||
function tablesFilter(){
|
||||
var value = document.getElementById('filter-field').value.toLowerCase();
|
||||
var value = qs('#filter-field').value.toLowerCase();
|
||||
if (value == tablesFilterValue) {
|
||||
return;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ function tablesFilter(){
|
|||
if (sessionStorage) {
|
||||
sessionStorage.setItem('adminer_tables_filter', value);
|
||||
}
|
||||
var tables = document.getElementById('tables').getElementsByTagName('li');
|
||||
var tables = qs('#tables').getElementsByTagName('li');
|
||||
for (var i = 0; i < tables.length; i++) {
|
||||
var a = tables[i].getElementsByTagName('a')[1];
|
||||
var text = tables[i].getAttribute('data-table-name');
|
||||
|
@ -60,10 +60,10 @@ function tablesFilterInput() {
|
|||
}
|
||||
|
||||
if (sessionStorage){
|
||||
var db = document.getElementById('dbs').getElementsByTagName('select')[0];
|
||||
var db = qs('#dbs').getElementsByTagName('select')[0];
|
||||
db = db.options[db.selectedIndex].text;
|
||||
if (db == sessionStorage.getItem('adminer_tables_filter_db') && sessionStorage.getItem('adminer_tables_filter')){
|
||||
document.getElementById('filter-field').value = sessionStorage.getItem('adminer_tables_filter');
|
||||
qs('#filter-field').value = sessionStorage.getItem('adminer_tables_filter');
|
||||
tablesFilter();
|
||||
}
|
||||
sessionStorage.setItem('adminer_tables_filter_db', db);
|
||||
|
|
|
@ -71,7 +71,7 @@ tinyMCE.init({
|
|||
return "<textarea$attrs id='fields-" . h($field["field"]) . "' rows='12' cols='50'>" . h($value) . "</textarea><script type='text/javascript'>
|
||||
tinyMCE.remove(tinyMCE.get('fields-" . js_escape($field["field"]) . "') || { });
|
||||
tinyMCE.execCommand('mceAddControl', true, 'fields-" . js_escape($field["field"]) . "');
|
||||
document.getElementById('form').onsubmit = function () {
|
||||
qs('#form').onsubmit = function () {
|
||||
tinyMCE.each(tinyMCE.editors, function (ed) {
|
||||
ed.remove();
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue