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

Make it easier to disable or replace keyboard actions. #670

Merged
merged 1 commit into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/mapInteractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ var mapInteractor = function (args) {
keyboard: {
actions: {
/* Specific actions can be disabled by removing them from this object
* or stting an empty list as the key bindings. Additional actions
* or setting an empty list as the key bindings. Additional actions
* can be added to the dictionary, each of which gets a list of key
* bindings. See Mousetrap documentation for special key names. */
'zoom.in': ['plus', 'shift+plus', 'shift+ctrl+plus', '=', 'shift+=', 'shift+ctrl+='],
Expand Down Expand Up @@ -225,6 +225,9 @@ var mapInteractor = function (args) {
if (args && args.momentum && args.momentum.actions) {
m_options.momentum.actions = $.extend(true, [], args.momentum.actions);
}
if (args && args.keyboard && args.keyboard.actions !== undefined) {
m_options.keyboard.actions = $.extend(true, {}, args.keyboard.actions);
}

// options supported:
// {
Expand Down
9 changes: 9 additions & 0 deletions tests/cases/mapInteractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1681,5 +1681,14 @@ describe('mapInteractor', function () {
keyboardSettings.focusHighlight = true;
expect(interactor.keyboard(keyboardSettings)).toBe(interactor);
expect(map.node().hasClass('highlight-focus')).toBe(true);

// test creating a interactor with a different set of keyboard actions
interactor = geo.mapInteractor({map: map, keyboard: {actions: {'zoom.0': ['1']}}});
triggered = 0;
interactor.simulateEvent('keyboard', {keys: '1'});
expect(triggered).toBe(1);
triggered = 0;
interactor.simulateEvent('keyboard', {keys: '2'});
expect(triggered).toBe(0);
});
});