src/hotkeys.js
function _add (combo, description, callback, action, allowIn, persistent) {

        // used to save original callback for "allowIn" wrapping:
        var _callback;

        // these elements are prevented by the default Mousetrap.stopCallback():
        var preventIn = ['INPUT', 'SELECT', 'TEXTAREA'];

        // Determine if object format was given:
        var objType = Object.prototype.toString.call(combo);

        if (objType === '[object Object]') {
          description = combo.description;
          callback    = combo.callback;
          action      = combo.action;
          persistent  = combo.persistent;
          allowIn     = combo.allowIn;
          combo       = combo.combo;
        }

        // no duplicates please
        _del(combo);

        // description is optional:
        if (description instanceof Function) {
          action = callback;
          callback = description;
          description = '$$undefined$$';
        } else if (angular.isUndefined(description)) {
          description = '$$undefined$$';
        }

        // any items added through the public API are for controllers
        // that persist through navigation, and thus undefined should mean
        // true in this case.
        if (persistent === undefined) {
          persistent = true;
        }
        // if callback is defined, then wrap it in a function
        // that checks if the event originated from a form element.
        // the function blocks the callback from executing unless the element is specified
        // in allowIn (emulates Mousetrap.stopCallback() on a per-key level)
        if (typeof callback === 'function') {

          // save the original callback
          _callback = callback;

          // make sure allowIn is an array
          if (!(allowIn instanceof Array)) {
            allowIn = [];
          }

          // remove anything from preventIn that's present in allowIn
          var index;
          for (var i=0; i < allowIn.length; i++) {
            allowIn[i] = allowIn[i].toUpperCase();
            index = preventIn.indexOf(allowIn[i]);
            if (index !== -1) {
              preventIn.splice(index, 1);
            }
          }

          // create the new wrapper callback
          callback = function(event) {
            var shouldExecute = true;

            // if the callback is executed directly `hotkey.get('w').callback()`
            // there will be no event, so just execute the callback.
            if (event) {
              var target = event.target || event.srcElement; // srcElement is IE only
              var nodeName = target.nodeName.toUpperCase();

              // check if the input has a mousetrap class, and skip checking preventIn if so
              if ((' ' + target.className + ' ').indexOf(' mousetrap ') > -1) {
                shouldExecute = true;
              } else {
                // don't execute callback if the event was fired from inside an element listed in preventIn
                for (var i=0; i<preventIn.length; i++) {
                  if (preventIn[i] === nodeName) {
                    shouldExecute = false;
                    break;
                  }
                }
              }
            }

            if (shouldExecute) {
              wrapApply(_callback.apply(this, arguments));
            }
          };
        }

        if (typeof(action) === 'string') {
          Mousetrap.bind(combo, wrapApply(callback), action);
        } else {
          Mousetrap.bind(combo, wrapApply(callback));
        }

        var hotkey = new Hotkey(combo, description, callback, action, allowIn, persistent);
        scope.hotkeys.push(hotkey);
        return hotkey;
      }
function _add (combo, description, callback, action, allowIn, persistent) {

        // used to save original callback for "allowIn" wrapping:
        var _callback;

        // these elements are prevented by the default Mousetrap.stopCallback():
        var preventIn = ['INPUT', 'SELECT', 'TEXTAREA'];

        // Determine if object format was given:
        var objType = Object.prototype.toString.call(combo);

        if (objType === '[object Object]') {
          description = combo.description;
          callback    = combo.callback;
          action      = combo.action;
          persistent  = combo.persistent;
          allowIn     = combo.allowIn;
          combo       = combo.combo;
        }

        // no duplicates please
        _del(combo);

        // description is optional:
        if (description instanceof Function) {
          action = callback;
          callback = description;
          description = '$$undefined$$';
        } else if (angular.isUndefined(description)) {
          description = '$$undefined$$';
        }

        // any items added through the public API are for controllers
        // that persist through navigation, and thus undefined should mean
        // true in this case.
        if (persistent === undefined) {
          persistent = true;
        }
        // if callback is defined, then wrap it in a function
        // that checks if the event originated from a form element.
        // the function blocks the callback from executing unless the element is specified
        // in allowIn (emulates Mousetrap.stopCallback() on a per-key level)
        if (typeof callback === 'function') {

          // save the original callback
          _callback = callback;

          // make sure allowIn is an array
          if (!(allowIn instanceof Array)) {
            allowIn = [];
          }

          // remove anything from preventIn that's present in allowIn
          var index;
          for (var i=0; i < allowIn.length; i++) {
            allowIn[i] = allowIn[i].toUpperCase();
            index = preventIn.indexOf(allowIn[i]);
            if (index !== -1) {
              preventIn.splice(index, 1);
            }
          }

          // create the new wrapper callback
          callback = function(event) {
            var shouldExecute = true;

            // if the callback is executed directly `hotkey.get('w').callback()`
            // there will be no event, so just execute the callback.
            if (event) {
              var target = event.target || event.srcElement; // srcElement is IE only
              var nodeName = target.nodeName.toUpperCase();

              // check if the input has a mousetrap class, and skip checking preventIn if so
              if ((' ' + target.className + ' ').indexOf(' mousetrap ') > -1) {
                shouldExecute = true;
              } else {
                // don't execute callback if the event was fired from inside an element listed in preventIn
                for (var i=0; i<preventIn.length; i++) {
                  if (preventIn[i] === nodeName) {
                    shouldExecute = false;
                    break;
                  }
                }
              }
            }

            if (shouldExecute) {
              wrapApply(_callback.apply(this, arguments));
            }
          };
        }

        if (typeof(action) === 'string') {
          Mousetrap.bind(combo, wrapApply(callback), action);
        } else {
          Mousetrap.bind(combo, wrapApply(callback));
        }

        var hotkey = new Hotkey(combo, description, callback, action, allowIn, persistent);
        scope.hotkeys.push(hotkey);
        return hotkey;
      }
function _add ( combo , description , callback , action , allowIn , persistent ) { // used to save original callback for "allowIn" wrapping: var _callback ; // these elements are prevented by the default Mousetrap.stopCallback(): var preventIn = [ 'INPUT' , 'SELECT' , 'TEXTAREA' ] ; // Determine if object format was given: var objType = Object . prototype . toString . call ( combo ) ; if ( objType === '[object Object]' ) { description = combo . description ; callback = combo . callback ; action = combo . action ; persistent = combo . persistent ; allowIn = combo . allowIn ; combo = combo . combo ; } // no duplicates please _del ( combo ) ; // description is optional: if ( description instanceof Function ) { action = callback ; callback = description ; description = '$$undefined$$' ; } else if ( angular . isUndefined ( description ) ) { description = '$$undefined$$' ; } // any items added through the public API are for controllers // that persist through navigation, and thus undefined should mean // true in this case. if ( persistent === undefined ) { persistent = true ; } // if callback is defined, then wrap it in a function // that checks if the event originated from a form element. // the function blocks the callback from executing unless the element is specified // in allowIn (emulates Mousetrap.stopCallback() on a per-key level) if ( typeof callback === 'function' ) { // save the original callback _callback = callback ; // make sure allowIn is an array if ( ! ( allowIn instanceof Array ) ) { allowIn = [ ] ; } // remove anything from preventIn that's present in allowIn var index ; for ( var i = 0 ; i < allowIn . length ; i ++ ) { allowIn [ i ] = allowIn [ i ] . toUpperCase ( ) ; index = preventIn . indexOf ( allowIn [ i ] ) ; if ( index !== - 1 ) { preventIn . splice ( index , 1 ) ; } } // create the new wrapper callback callback = function ( event ) { var shouldExecute = true ; // if the callback is executed directly `hotkey.get('w').callback()` // there will be no event, so just execute the callback. if ( event ) { var target = event . target || event . srcElement ; // srcElement is IE only var nodeName = target . nodeName . toUpperCase ( ) ; // check if the input has a mousetrap class, and skip checking preventIn if so if ( ( ' ' + target . className + ' ' ) . indexOf ( ' mousetrap ' ) > - 1 ) { shouldExecute = true ; } else { // don't execute callback if the event was fired from inside an element listed in preventIn for ( var i = 0 ; i < preventIn . length ; i ++ ) { if ( preventIn [ i ] === nodeName ) { shouldExecute = false ; break ; } } } } if ( shouldExecute ) { wrapApply ( _callback . apply ( this , arguments ) ) ; } } ; } if ( typeof ( action ) === 'string' ) { Mousetrap . bind ( combo , wrapApply ( callback ) , action ) ; } else { Mousetrap . bind ( combo , wrapApply ( callback ) ) ; } var hotkey = new Hotkey ( combo , description , callback , action , allowIn , persistent ) ; scope . hotkeys . push ( hotkey ) ; return hotkey ; }
Creates a new Hotkey and creates the Mousetrap binding

@param {string}   combo       mousetrap key binding
@param {string}   description description for the help menu
@param {Function} callback    method to call when key is pressed
@param {string}   action      the type of event to listen for (for mousetrap)
@param {array}    allowIn     an array of tag names to allow this combo in ('INPUT', 'SELECT', and/or 'TEXTAREA')
@param {boolean}  persistent  if true, the binding is preserved upon route changes
Creates a new Hotkey and creates the Mousetrap binding