qutebrowser/scripts/cycle-inputs.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-12-31 15:47:42 +01:00
/* Cycle <input> text boxes.
* works with the types defined in 'types'.
* Note: Does not work for <textarea>.
2018-01-17 20:32:05 +01:00
*
* Example keybind:
2017-12-31 15:47:42 +01:00
* CYCLE_INPUTS = "jseval -q -f ~/.config/qutebrowser/cycle-inputs.js"
* config.bind('gi', CYCLE_INPUTS)
*
* By dive on freenode <dave@dawoodfall.net>
*/
2018-01-17 20:32:05 +01:00
"use strict";
2017-12-31 15:47:42 +01:00
var inputs = document.getElementsByTagName("input");
var types = /text|password|date|email|month|number|range|search|tel|time|url|week/;
var hidden = /hidden/;
2018-01-17 20:32:05 +01:00
var found = false;
2018-01-17 20:41:54 +01:00
var i = 0;
var k = 0;
2017-12-31 15:47:42 +01:00
function ishidden(el) {
2018-01-17 20:32:05 +01:00
return hidden.test(el.attributes.value) || el.offsetParent === null;
2017-12-31 15:47:42 +01:00
}
2018-01-17 20:41:54 +01:00
for (i = 0; i < inputs.length; i++) {
if (inputs[i] === document.activeElement) {
for (k = i + 1; k < inputs.length; k++) {
if (!ishidden(inputs[k]) && types.test(inputs[k].type)) {
inputs[k].focus();
2018-01-17 20:32:05 +01:00
found = true;
break;
}
}
break;
}
2017-12-31 15:47:42 +01:00
}
2018-01-17 20:32:05 +01:00
if (!found) {
2018-01-17 20:41:54 +01:00
for (i = 0; i < inputs.length; i++) {
if (!ishidden(inputs[i]) && types.test(inputs[i].type)) {
inputs[i].focus();
2018-01-17 20:32:05 +01:00
break;
}
}
2017-12-31 15:47:42 +01:00
}
2018-01-17 20:32:05 +01:00
// vim: tw=0 expandtab tabstop=4 softtabstop=4 shiftwidth=4