[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/js/ -> ieEscGuard.js (source)

   1  /**
   2   * Javascript code for attaching an onkeydown listener to textarea and
   3   * text input elements to prevent loss of data when the user hits the
   4   * ESC key.
   5   *
   6   * $Horde: horde/js/ieEscGuard.js,v 1.1.2.3 2005/10/18 11:33:38 jan Exp $
   7   *
   8   * See the enclosed file COPYING for license information (LGPL). If you did not
   9   * receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  10   */
  11  
  12  /* This code is only relevant for IE. Therefore try not to do anything
  13   * if the user isn't using IE, even if this script is included. This
  14   * check will catch some browsers that are not IE but identify
  15   * themselves as IE. Hopefully if they pass through they support what
  16   * IE supports. */
  17  if (navigator.appVersion.indexOf('MSIE') != -1 && document.all) {
  18      /* We do everything onload so that the entire document is present
  19       * before we start searching it. */
  20      window.attachEvent('onload', guard);
  21  }
  22  
  23  /**
  24   * Finds all text inputs (input type="text") and textarea tags, and
  25   * attaches the onkeydown listener to them to avoid ESC clearing the
  26   * text.
  27   */
  28  function guard()
  29  {
  30      /* Finds all textareas. */
  31      var textareas = document.all.tags('TEXTAREA');
  32      for (var i = 0; i < textareas.length; i++) {
  33          textareas[i].attachEvent('onkeydown', disableEscape);
  34      }
  35  
  36      /* Finds _all_ <input> tags. */
  37      var inputs = document.all.tags('INPUT');
  38      for (var i = 0; i < inputs.length; i++) {
  39          /* Only attach to <input type="text"> tags. */
  40          if (inputs[i].type == 'text') {
  41              inputs[i].attachEvent('onkeydown', disableEscape);
  42          }
  43      }
  44  }
  45  
  46  /**
  47   * Returns false if the user hit the ESC key, preventing IE from
  48   * blanking the field. Otherwise returns true.
  49   *
  50   * return boolean  Whether or not to allow the key event.
  51   */
  52  function disableEscape()
  53  {
  54      return window.event.keyCode != 27;
  55  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7