Files
iD/modules/ui/zoom_to_selection.js
Quincy Morgan a1af118f0e Ensure locales and presets are loaded before the UI loads (close #7406)
Consolidate localization behavior and init to a coreLocalizer function and singleton
Explicitly support `en-US` locale
Rename coreData to coreFileFetcher and export a singleton rather than using a property of coreContext
Add `apiConnections` property of coreContext to simplify adding a source switcher
Replace some init functions with re-callable, promise-supporting `ensureLoaded` functions
Make coreContext itself load the UI if a container has been specified at init time
Fix code tests
2020-03-31 12:23:31 -07:00

43 lines
1.1 KiB
JavaScript

import { select as d3_select } from 'd3-selection';
import { t, localizer } from '../core/localizer';
import { uiTooltip } from './tooltip';
import { svgIcon } from '../svg/icon';
export function uiZoomToSelection(context) {
var _button = d3_select(null);
function click() {
if (d3_select(this).classed('disabled')) return;
var mode = context.mode();
if (mode && mode.zoomToSelected) {
mode.zoomToSelected();
}
}
function setEnabledState() {
var mode = context.mode();
var isEnabled = mode && !!mode.zoomToSelected;
_button.classed('disabled', !isEnabled);
}
context.on('enter.uiZoomToSelection', setEnabledState);
return function(selection) {
_button = selection
.append('button')
.on('click', click)
.call(svgIcon('#iD-icon-framed-dot', 'light'))
.call(uiTooltip()
.placement((localizer.textDirection() === 'rtl') ? 'right' : 'left')
.title(t('inspector.zoom_to.title'))
.keys([t('inspector.zoom_to.key')])
);
setEnabledState();
};
}