mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-19 23:14:47 +02:00
32f8274929
Update `text` functions to `html` to support inserting the `span` elements Specify `html: false` for various instances where a `span` is not desired, e.g. `placeholder` and `title` attributes
38 lines
1.2 KiB
JavaScript
38 lines
1.2 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, html: false });
|
|
|
|
const _placeholder = _this.placeholder;
|
|
_this.placeholder = () => _this.t('placeholder', { 'default': _placeholder, html: false });
|
|
|
|
_this.originalTerms = (_this.terms || []).join();
|
|
|
|
_this.terms = () => _this.t('terms', { 'default': _this.originalTerms, html: false })
|
|
.toLowerCase().trim().split(/\s*,+\s*/);
|
|
|
|
|
|
return _this;
|
|
}
|