mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
Add a keybinding behavior for operations
This commit is contained in:
@@ -8,6 +8,7 @@ export { behaviorEdit } from './edit';
|
||||
export { behaviorHash } from './hash';
|
||||
export { behaviorHover } from './hover';
|
||||
export { behaviorLasso } from './lasso';
|
||||
export { behaviorOperation } from './operation';
|
||||
export { behaviorPaste } from './paste';
|
||||
export { behaviorSelect } from './select';
|
||||
export { behaviorTail } from './tail';
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import * as d3 from 'd3';
|
||||
import { d3keybinding } from '../lib/d3.keybinding.js';
|
||||
|
||||
|
||||
/* Creates a keybinding behavior for an operation */
|
||||
export function behaviorOperation(context) {
|
||||
var which, keybinding;
|
||||
|
||||
|
||||
var behavior = function () {
|
||||
if (which) {
|
||||
keybinding = d3keybinding('behavior.key.' + which.id);
|
||||
keybinding.on(which.keys, function() {
|
||||
d3.event.preventDefault();
|
||||
if (!(context.inIntro() || which.disabled())) {
|
||||
which();
|
||||
}
|
||||
});
|
||||
d3.select(document).call(keybinding);
|
||||
}
|
||||
return behavior;
|
||||
};
|
||||
|
||||
|
||||
behavior.off = function() {
|
||||
if (keybinding) {
|
||||
d3.select(document).call(keybinding.off);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
behavior.which = function (_) {
|
||||
if (!arguments.length) return which;
|
||||
which = _;
|
||||
return behavior;
|
||||
};
|
||||
|
||||
|
||||
return behavior;
|
||||
}
|
||||
Reference in New Issue
Block a user