mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-30 19:59:35 +02:00
Use context.keybinding for keybindings that don't change
(closes #5487)
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user