mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-23 14:14:11 +00:00
Switch only phone placeholder asynchronously
This commit is contained in:
@@ -4,79 +4,60 @@ iD.ui.preset.tel =
|
||||
iD.ui.preset.email =
|
||||
iD.ui.preset.url = function(field, context) {
|
||||
|
||||
var dispatch = d3.dispatch('init', 'change'),
|
||||
var dispatch = d3.dispatch('change'),
|
||||
input,
|
||||
entity,
|
||||
isInitialized;
|
||||
entity;
|
||||
|
||||
function i(selection) {
|
||||
isInitialized = false;
|
||||
var fieldId = 'preset-input-' + field.id;
|
||||
|
||||
input = selection.selectAll('input')
|
||||
.data([0]);
|
||||
|
||||
input.enter().append('input')
|
||||
.attr('type', field.type)
|
||||
.attr('id', fieldId)
|
||||
.attr('placeholder', field.placeholder() || t('inspector.unknown'));
|
||||
|
||||
input
|
||||
.on('input', change(true))
|
||||
.on('blur', change())
|
||||
.on('change', change());
|
||||
|
||||
if (field.type === 'tel') {
|
||||
var center = entity.extent(context.graph()).center();
|
||||
|
||||
iD.services.nominatim().countryCode(center, function (err, countryCode) {
|
||||
|
||||
input.enter().append('input')
|
||||
.attr('type', field.type)
|
||||
.attr('id', 'preset-input-' + field.id)
|
||||
.attr('placeholder',
|
||||
iD.data.phoneFormats[countryCode] ||
|
||||
field.placeholder() ||
|
||||
t('inspector.unknown'));
|
||||
|
||||
input
|
||||
.on('input', change(true))
|
||||
.on('blur', change())
|
||||
.on('change', change());
|
||||
|
||||
dispatch.init();
|
||||
isInitialized = true;
|
||||
if (err || !iD.data.phoneFormats[countryCode]) return;
|
||||
selection.selectAll('#' + fieldId)
|
||||
.attr('placeholder', iD.data.phoneFormats[countryCode]);
|
||||
});
|
||||
} else {
|
||||
input.enter().append('input')
|
||||
.attr('type', field.type)
|
||||
.attr('id', 'preset-input-' + field.id)
|
||||
.attr('placeholder', field.placeholder() || t('inspector.unknown'));
|
||||
|
||||
input
|
||||
.on('input', change(true))
|
||||
.on('blur', change())
|
||||
.on('change', change());
|
||||
} else if (field.type === 'number') {
|
||||
input.attr('type', 'text');
|
||||
|
||||
if (field.type === 'number') {
|
||||
input.attr('type', 'text');
|
||||
var spinControl = selection.selectAll('.spin-control')
|
||||
.data([0]);
|
||||
|
||||
var spinControl = selection.selectAll('.spin-control')
|
||||
.data([0]);
|
||||
var enter = spinControl.enter().append('div')
|
||||
.attr('class', 'spin-control');
|
||||
|
||||
var enter = spinControl.enter().append('div')
|
||||
.attr('class', 'spin-control');
|
||||
enter.append('button')
|
||||
.datum(1)
|
||||
.attr('class', 'increment')
|
||||
.attr('tabindex', -1);
|
||||
|
||||
enter.append('button')
|
||||
.datum(1)
|
||||
.attr('class', 'increment')
|
||||
.attr('tabindex', -1);
|
||||
enter.append('button')
|
||||
.datum(-1)
|
||||
.attr('class', 'decrement')
|
||||
.attr('tabindex', -1);
|
||||
|
||||
enter.append('button')
|
||||
.datum(-1)
|
||||
.attr('class', 'decrement')
|
||||
.attr('tabindex', -1);
|
||||
|
||||
spinControl.selectAll('button')
|
||||
.on('click', function(d) {
|
||||
d3.event.preventDefault();
|
||||
var num = parseInt(input.node().value || 0, 10);
|
||||
if (!isNaN(num)) input.node().value = num + d;
|
||||
change()();
|
||||
});
|
||||
}
|
||||
|
||||
dispatch.init();
|
||||
isInitialized = true;
|
||||
spinControl.selectAll('button')
|
||||
.on('click', function(d) {
|
||||
d3.event.preventDefault();
|
||||
var num = parseInt(input.node().value || 0, 10);
|
||||
if (!isNaN(num)) input.node().value = num + d;
|
||||
change()();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,13 +76,7 @@ iD.ui.preset.url = function(field, context) {
|
||||
};
|
||||
|
||||
i.tags = function(tags) {
|
||||
if (isInitialized) {
|
||||
input.value(tags[field.key] || '');
|
||||
} else {
|
||||
dispatch.on('init', function () {
|
||||
input.value(tags[field.key] || '');
|
||||
});
|
||||
}
|
||||
input.value(tags[field.key] || '');
|
||||
};
|
||||
|
||||
i.focus = function() {
|
||||
|
||||
Reference in New Issue
Block a user