mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-28 23:10:40 +01:00
- preset data is no longer bundled into iD.js - some code pathways commented out re: external presets - many changes so that tests can run without presets at start, or async - still need to make sure fallbacks are always there (point, line, area, etc)
34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
import { t } from '../util/locale';
|
|
import { utilSafeClassName } from '../util/util';
|
|
|
|
|
|
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 === geom;
|
|
|
|
_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;
|
|
}
|