Use context.keybinding for keybindings that don't change

(closes #5487)
This commit is contained in:
Bryan Housel
2018-11-13 20:57:21 -05:00
parent bb30cbf555
commit 152022aec4
37 changed files with 252 additions and 319 deletions
+35 -41
View File
@@ -1,57 +1,51 @@
import {
event as d3_event,
select as d3_select
} from 'd3-selection';
import { event as d3_event } from 'd3-selection';
import { uiFlash } from '../ui';
import { utilKeybinding } from '../util';
/* Creates a keybinding behavior for an operation */
export function behaviorOperation() {
var keybinding;
export function behaviorOperation(context) {
var _operation;
var behavior = function () {
function keypress() {
d3_event.preventDefault();
var disabled = _operation.disabled();
var flash;
if (disabled) {
flash = uiFlash()
.duration(4000)
.iconName('#iD-operation-' + _operation.id)
.iconClass('operation disabled')
.text(_operation.tooltip);
flash();
} else {
flash = uiFlash()
.duration(2000)
.iconName('#iD-operation-' + _operation.id)
.iconClass('operation')
.text(_operation.annotation() || _operation.title);
flash();
_operation();
}
}
function behavior() {
if (_operation && _operation.available()) {
keybinding = utilKeybinding('behavior.key.' + _operation.id);
keybinding.on(_operation.keys, function() {
d3_event.preventDefault();
var disabled = _operation.disabled();
var flash;
if (disabled) {
flash = uiFlash()
.duration(4000)
.iconName('#iD-operation-' + _operation.id)
.iconClass('operation disabled')
.text(_operation.tooltip);
flash();
} else {
flash = uiFlash()
.duration(2000)
.iconName('#iD-operation-' + _operation.id)
.iconClass('operation')
.text(_operation.annotation() || _operation.title);
flash();
_operation();
}
});
d3_select(document).call(keybinding);
context.keybinding()
.on(_operation.keys, keypress);
}
return behavior;
};
}
behavior.off = function() {
if (keybinding) {
d3_select(document).call(keybinding.off);
}
context.keybinding()
.off(_operation.keys);
};