Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiplied bindings #35

Closed
ujovlado opened this issue May 29, 2014 · 4 comments
Closed

multiplied bindings #35

ujovlado opened this issue May 29, 2014 · 4 comments
Labels

Comments

@ujovlado
Copy link

Hi, we'reusing angular-hotkyes in our project.

On site index we have welcome page, on another site home there are some actions with added hotkeys.

When I navigate from index to home and show help through ? everything is fine. Then I navigate to index and back to home and keys are doubled (then tripled, ... etc.)

@chieffancypants
Copy link
Owner

They shouldn't be -- there are test cases to prevent that. Are you defining the hotkeys through the routing? You may just be setting up persistent hotkeys.

@ujovlado
Copy link
Author

Hi, thanks for response. Hotkeys are defined only in one controller, because only in that controller are needed. But I used ui-router (https://github.com/angular-ui/ui-router), maybe that causing a problem. I'll try to do the same with standard router.

@chieffancypants
Copy link
Owner

No -- controller-based hotkeys are persistent by default, as they are used for things like a navigation bar which is present on every page. It's related to #32 but can be fixed by manually specifying that the hotkey is not intended to be persistent. This is the method signature:

/**
 * 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
 */
function _add (combo, description, callback, action, allowIn, persistent) {

So simply pass in persistent: false in the object or function argument that you pass to hotkeys.add:

hotkeys.add({
  combo: 'w',
  description: '....',
  callback: function() {},
  persistent: false
});

@ujovlado
Copy link
Author

ujovlado commented Jun 5, 2014

I don't know how it happened, but it was browser-related issue ... in newer version it works fine. Thanks for help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants