views:

36

answers:

1

hi I am writing a javascript widget which handles keyboard events. The issue in question arises when i show a div and want to hide it when someone presses esc.

what's the best way to achieve the following (i am using jquery in this project )

var escToExit = function(e){
   // code to check for esc
  // i then want to call the instance of widget that is linked to this function
}
var widget = {
  show : function(){
    $(document).keyup(escToExit);
  },
  hide : function(){
    //hide code here
  }
}

thanks

A: 

Edit

By value:

var escToExit = function(e){
  e.data.wpass; // here is your ref
  // rest of func
}

var widget = {
  show : fuction() {
    $(document).bind('keyup', {wpass : widget}, escToExit);
  // rest of obj
}

See

http://api.jquery.com/bind/

and

http://api.jquery.com/trigger/

Hogan
sorry, this doesn't refer to the widget object
Dave Taylor