Added key shortcut Ctrl+Shift+F to focus filter field and disabled enter key
This commit is contained in:
parent
f4532fa957
commit
e62f5e5e52
|
@ -6,43 +6,29 @@
|
||||||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
|
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
|
||||||
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
|
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class AdminerTablesFilter {
|
class AdminerTablesFilter {
|
||||||
function tablesPrint($tables) { ?>
|
function tablesPrint($tables) { ?>
|
||||||
<fieldset class="jsonly" style="margin-left: .8em;">
|
|
||||||
<legend><?php echo lang('Filter tables'); ?></legend>
|
|
||||||
<div>
|
|
||||||
<input type="search" id="filter-field" autocomplete="off">
|
|
||||||
<input type="button" id="filter-field-reset" value="<?php echo lang('Clear'); ?>">
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<script<?php echo nonce(); ?>>
|
<script<?php echo nonce(); ?>>
|
||||||
(function() {
|
var tablesFilterTimeout = null;
|
||||||
|
var tablesFilterValue = '';
|
||||||
|
|
||||||
var timeout;
|
function tablesFilter(){
|
||||||
var lastValue = '';
|
var value = qs('#filter-field').value.toLowerCase();
|
||||||
var filterField = qs('#filter-field');
|
if (value == tablesFilterValue) {
|
||||||
|
|
||||||
function filter() {
|
|
||||||
timeout && (timeout = null);
|
|
||||||
var value = filterField.value.toLowerCase();
|
|
||||||
if (value == lastValue) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lastValue = value;
|
tablesFilterValue = value;
|
||||||
if (value != '') {
|
if (value != '') {
|
||||||
var reg = (value + '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
var reg = (value + '').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1');
|
||||||
reg = new RegExp('('+ reg + ')', 'gi');
|
reg = new RegExp('('+ reg + ')', 'gi');
|
||||||
}
|
}
|
||||||
if (window.sessionStorage) {
|
if (sessionStorage) {
|
||||||
sessionStorage.setItem('adminer_tables_filter', value);
|
sessionStorage.setItem('adminer_tables_filter', value);
|
||||||
}
|
}
|
||||||
var tables = qsa('li', qs('#tables'));
|
var tables = qsa('li', qs('#tables'));
|
||||||
var a;
|
|
||||||
var text;
|
|
||||||
for (var i = 0; i < tables.length; i++) {
|
for (var i = 0; i < tables.length; i++) {
|
||||||
text = tables[i].getAttribute('data-table-name');
|
var a = null;
|
||||||
|
var text = tables[i].getAttribute('data-table-name');
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
a = qsa('a', tables[i])[1];
|
a = qsa('a', tables[i])[1];
|
||||||
text = a.innerHTML.trim();
|
text = a.innerHTML.trim();
|
||||||
|
@ -62,32 +48,45 @@ function filter() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
filterField.addEventListener('input', function input() {
|
function tablesFilterInput() {
|
||||||
timeout && window.clearTimeout(timeout);
|
window.clearTimeout(tablesFilterTimeout);
|
||||||
timeout = window.setTimeout(filter, 200);
|
tablesFilterTimeout = window.setTimeout(tablesFilter, 200);
|
||||||
});
|
}
|
||||||
|
|
||||||
qs('#filter-field-reset').addEventListener('click', function() {
|
sessionStorage && document.addEventListener('DOMContentLoaded', function () {
|
||||||
filterField.value = '';
|
if (qs('#dbs') != null) {
|
||||||
filterField.dispatchEvent(new Event('input'));
|
var db = qs('#dbs').querySelector('select');
|
||||||
});
|
db = db.options[db.selectedIndex].text;
|
||||||
|
if (db == sessionStorage.getItem('adminer_tables_filter_db') && sessionStorage.getItem('adminer_tables_filter')){
|
||||||
window.sessionStorage && document.addEventListener('DOMContentLoaded', function restore() {
|
qs('#filter-field').value = sessionStorage.getItem('adminer_tables_filter');
|
||||||
var db = qs('#dbs select');
|
tablesFilter();
|
||||||
var value;
|
}
|
||||||
db = db.options[db.selectedIndex].text;
|
sessionStorage.setItem('adminer_tables_filter_db', db);
|
||||||
if (
|
|
||||||
db == sessionStorage.getItem('adminer_tables_filter_db')
|
|
||||||
&& (value = sessionStorage.getItem('adminer_tables_filter'))
|
|
||||||
) {
|
|
||||||
filterField.value = value;
|
|
||||||
filter();
|
|
||||||
}
|
}
|
||||||
sessionStorage.setItem('adminer_tables_filter_db', db);
|
document.addEventListener('keyup', function(event) {
|
||||||
|
if (event.ctrlKey && event.shiftKey && event.key == 'F') {
|
||||||
|
qs('#filter-field').focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
qs('#filter-field').addEventListener('keydown', function(event) {
|
||||||
|
if (event.key == 'Enter' || event.keyCode == 13 || event.which == 13) {
|
||||||
|
event.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<fieldset style="margin-left: .8em;">
|
||||||
|
<legend><?php echo lang('Filter tables'); ?></legend>
|
||||||
|
<div>
|
||||||
|
<input type="search" id="filter-field" autocomplete="off" placeholder="Ctrl + Shift + F"><?php echo script("qs('#filter-field').oninput = tablesFilterInput;"); ?>
|
||||||
|
<input type="button" id="filter-field-reset" value="<?php echo lang('Clear'); ?>">
|
||||||
|
<?php echo script("qs('#filter-field-reset').onclick = function() { qs('#filter-field').value = ''; qs('#filter-field').dispatchEvent(new Event('input')); }"); ?>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue