File: ieEscGuard.js

package info (click to toggle)
horde3 3.1.3-4etch7
  • links: PTS
  • area: main
  • in suites: etch
  • size: 22,876 kB
  • ctags: 18,071
  • sloc: php: 75,151; xml: 2,979; sql: 1,069; makefile: 79; sh: 64
file content (55 lines) | stat: -rw-r--r-- 1,825 bytes parent folder | download | duplicates (2)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
 * Javascript code for attaching an onkeydown listener to textarea and
 * text input elements to prevent loss of data when the user hits the
 * ESC key.
 *
 * $Horde: horde/js/ieEscGuard.js,v 1.1.2.3 2005/10/18 11:33:38 jan Exp $
 *
 * See the enclosed file COPYING for license information (LGPL). If you did not
 * receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */

/* This code is only relevant for IE. Therefore try not to do anything
 * if the user isn't using IE, even if this script is included. This
 * check will catch some browsers that are not IE but identify
 * themselves as IE. Hopefully if they pass through they support what
 * IE supports. */
if (navigator.appVersion.indexOf('MSIE') != -1 && document.all) {
    /* We do everything onload so that the entire document is present
     * before we start searching it. */
    window.attachEvent('onload', guard);
}

/**
 * Finds all text inputs (input type="text") and textarea tags, and
 * attaches the onkeydown listener to them to avoid ESC clearing the
 * text.
 */
function guard()
{
    /* Finds all textareas. */
    var textareas = document.all.tags('TEXTAREA');
    for (var i = 0; i < textareas.length; i++) {
        textareas[i].attachEvent('onkeydown', disableEscape);
    }

    /* Finds _all_ <input> tags. */
    var inputs = document.all.tags('INPUT');
    for (var i = 0; i < inputs.length; i++) {
        /* Only attach to <input type="text"> tags. */
        if (inputs[i].type == 'text') {
            inputs[i].attachEvent('onkeydown', disableEscape);
        }
    }
}

/**
 * Returns false if the user hit the ESC key, preventing IE from
 * blanking the field. Otherwise returns true.
 *
 * return boolean  Whether or not to allow the key event.
 */
function disableEscape()
{
    return window.event.keyCode != 27;
}