Files
iD/modules/ui/fields/textarea.js
2016-08-26 01:15:07 -04:00

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');
}