Print Friendly

Class YAHOO.ext.KeyMap

Package:YAHOO.ext
Class:KeyMap
Extends:Object
Defined In:yutil.js
Handles mapping keys to actions for an element. One key map can be used for multiple actions. A KeyMap can also handle a string representation of keys.
Usage:
// map one key by key code
 var map = new YAHOO.ext.KeyMap('my-element', {
     key: 13,
     fn: myHandler,
     scope: myObject
 });
 
 // map multiple keys to one action by string
 var map = new YAHOO.ext.KeyMap('my-element', {
     key: "a\r\n\t",
     fn: myHandler,
     scope: myObject
 });
 
 // map multiple keys to multiple actions by strings and array of codes
 var map = new YAHOO.ext.KeyMap('my-element', [
    {
        key: [10,13],
        fn: function(){ alert('Return was pressed'); }
    }, {
        key: "abc",
        fn: function(){ alert('a, b or c was pressed'); }
    }, {
        key: "\t",
        ctrl:true,
        shift:true,
        fn: function(){ alert('Control + shift + tab was pressed.'); }
    }
]);
Note: A KepMap starts enabled

Public Properties

This class has no public properties.

Public Methods

Method Defined By
  KeyMap(String/HTMLElement/YAHOO.ext.Element el, Object config, [String eventName]) KeyMap
  addBinding(Object config) : void KeyMap
Add a new binding to this KeyMap
  disable() : void KeyMap
Disable this KeyMap
  enable() : void KeyMap
Enable this KeyMap
  isEnabled() : Boolean KeyMap
Returns true if this KepMap is enabled

Public Events

This class has no public events.

Constructor Details

KeyMap

public function KeyMap(String/HTMLElement/YAHOO.ext.Element el, Object config, [String eventName])
Parameters:
  • el : String/HTMLElement/YAHOO.ext.Element
    The element to bind to
  • config : Object
    The config
  • eventName : String
    (optional) The event to bind to (Defaults to "keydown").

Method Details

addBinding

public function addBinding(Object config)
Add a new binding to this KeyMap
Parameters:
  • config : Object
    A single KeyMap config
Returns:
  • void
This method is defined by KeyMap.

disable

public function disable()
Disable this KeyMap
Parameters:
  • None.
Returns:
  • void
This method is defined by KeyMap.

enable

public function enable()
Enable this KeyMap
Parameters:
  • None.
Returns:
  • void
This method is defined by KeyMap.

isEnabled

public function isEnabled()
Returns true if this KepMap is enabled
Parameters:
  • None.
Returns:
  • Boolean
This method is defined by KeyMap.

yui-ext - Copyright © 2006 Jack Slocum. | Yahoo! UI - Copyright © 2006 Yahoo! Inc.
All rights reserved.