mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 09:42:56 +00:00
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
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
import { t } from '../core/localizer';
|
|
import { utilSafeClassName } from '../util/util';
|
|
|
|
|
|
//
|
|
// `presetField` decorates a given `field` Object
|
|
// with some extra methods for searching and matching geometry
|
|
//
|
|
export function presetField(fieldID, field) {
|
|
let _this = Object.assign({}, field); // shallow copy
|
|
|
|
_this.id = fieldID;
|
|
|
|
// for use in classes, element ids, css selectors
|
|
_this.safeid = utilSafeClassName(fieldID);
|
|
|
|
_this.matchGeometry = (geom) => !_this.geometry || _this.geometry.indexOf(geom) !== -1;
|
|
|
|
_this.matchAllGeometry = (geometries) => {
|
|
return !_this.geometry || geometries.every(geom => _this.geometry.indexOf(geom) !== -1);
|
|
};
|
|
|
|
_this.t = (scope, options) => t(`presets.fields.${fieldID}.${scope}`, options);
|
|
|
|
_this.label = () => _this.overrideLabel || _this.t('label', { 'default': fieldID });
|
|
|
|
const _placeholder = _this.placeholder;
|
|
_this.placeholder = () => _this.t('placeholder', { 'default': _placeholder });
|
|
|
|
_this.originalTerms = (_this.terms || []).join();
|
|
|
|
_this.terms = () => _this.t('terms', { 'default': _this.originalTerms })
|
|
.toLowerCase().trim().split(/\s*,+\s*/);
|
|
|
|
|
|
return _this;
|
|
}
|