mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 09:42:56 +00:00
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import * as d3 from 'd3';
|
|
import { getSetValue } from '../../util/get_set_value';
|
|
import { rebind } from '../../util/rebind';
|
|
import { t } from '../../util/locale';
|
|
|
|
export function textarea(field) {
|
|
var dispatch = d3.dispatch('change'),
|
|
input;
|
|
|
|
function textarea(selection) {
|
|
input = selection.selectAll('textarea')
|
|
.data([0]);
|
|
|
|
input.enter().append('textarea')
|
|
.attr('id', 'preset-input-' + field.id)
|
|
.attr('placeholder', field.placeholder() || t('inspector.unknown'))
|
|
.attr('maxlength', 255);
|
|
|
|
input
|
|
.on('input', change(true))
|
|
.on('blur', change())
|
|
.on('change', change());
|
|
}
|
|
|
|
function change(onInput) {
|
|
return function() {
|
|
var t = {};
|
|
t[field.key] = getSetValue(input) || undefined;
|
|
dispatch.call('change', this, t, onInput);
|
|
};
|
|
}
|
|
|
|
textarea.tags = function(tags) {
|
|
getSetValue(input, tags[field.key] || '');
|
|
};
|
|
|
|
textarea.focus = function() {
|
|
input.node().focus();
|
|
};
|
|
|
|
return rebind(textarea, dispatch, 'on');
|
|
}
|