about summary refs log tree commit diff stats
path: root/input-focus.js
blob: 323efd0ca274f1ab254b52c4b855419e145dffd6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
    (c) 2009 by Leon Winter
    (c) 2009 by Hannes Schueller
    see LICENSE file
*/

function vimprobable_v(e, y) {
    t = e.nodeName.toLowerCase();
    if((t == 'input' && /^(text|password|checkbox|radio)$/.test(e.type))
    || /^(select|textarea)$/.test(t)
    || e.contentEditable == 'true')
        console.log('insertmode_'+(y=='focus'?'on':'off'));
}

if(document.activeElement)
    vimprobable_v(document.activeElement,'focus');

vimprobable_m=['focus','blur'];

if (document.getElementsByTagName("body")[0] !== null && typeof(document.getElementsByTagName("body")[0]) == "object") {
    for(i in vimprobable_m)
        document.getElementsByTagName('body')[0].addEventListener(vimprobable_m[i], function(x) {
            vimprobable_v(x.target,x.type);
        }, true);
}

self.onunload = function() {
    vimprobable_v(document.activeElement, '');
};