mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
This is because, like tooltip(), it doesn't always make sense to call it, and it should never get called if the operation is not available.
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
import * as d3 from 'd3';
|
|
import { d3keybinding } from '../lib/d3.keybinding.js';
|
|
import { uiFlash } from '../ui/index';
|
|
|
|
|
|
/* Creates a keybinding behavior for an operation */
|
|
export function behaviorOperation(context) {
|
|
var which, keybinding;
|
|
|
|
|
|
var behavior = function () {
|
|
if (which && which.available() && !context.inIntro()) {
|
|
keybinding = d3keybinding('behavior.key.' + which.id);
|
|
keybinding.on(which.keys, function() {
|
|
d3.event.preventDefault();
|
|
var disabled = which.disabled();
|
|
if (disabled) {
|
|
uiFlash(2500, 500).text(which.tooltip);
|
|
} else {
|
|
var annotation = which.annotation() || which.title;
|
|
uiFlash(1500, 250).text(annotation);
|
|
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;
|
|
}
|