mirror of
https://github.com/FoggedLens/iD.git
synced 2026-06-01 12:41:36 +02:00
Calculate address field widths
This commit is contained in:
@@ -126,4 +126,4 @@ js/lib/d3.v3.js: $(D3_FILES)
|
||||
@echo 'd3 rebuilt. Please reapply 7e2485d, 4da529f, and 223974d'
|
||||
|
||||
js/lib/lodash.js:
|
||||
node_modules/.bin/lodash --debug --output $@ include="any,assign,bind,clone,compact,contains,debounce,difference,each,every,extend,filter,find,first,forEach,groupBy,indexOf,intersection,isEmpty,isEqual,isFunction,keys,last,map,omit,pairs,pluck,reject,some,throttle,union,uniq,unique,values,without,flatten,value,chain,cloneDeep,merge,pick" exports="global,node"
|
||||
node_modules/.bin/lodash --debug --output $@ include="any,assign,bind,clone,compact,contains,debounce,difference,each,every,extend,filter,find,first,forEach,groupBy,indexOf,intersection,isEmpty,isEqual,isFunction,keys,last,map,omit,pairs,pluck,reject,some,throttle,union,uniq,unique,values,without,flatten,value,chain,cloneDeep,merge,pick,reduce" exports="global,node"
|
||||
|
||||
-20
@@ -1522,26 +1522,6 @@ input[type=number] {
|
||||
border-radius: 0 0 4px 0;
|
||||
}
|
||||
|
||||
.form-field .addr-housename {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.form-field .addr-housenumber {
|
||||
width: 33.3333%;
|
||||
}
|
||||
|
||||
.form-field .addr-street {
|
||||
width: 66.6666%;
|
||||
}
|
||||
|
||||
.form-field .addr-city {
|
||||
width: 66.6666%;
|
||||
}
|
||||
|
||||
.form-field .addr-postcode {
|
||||
width: 33.3333%;
|
||||
}
|
||||
|
||||
/* Restrictions editor */
|
||||
|
||||
.form-field-restrictions .preset-input-wrap {
|
||||
|
||||
@@ -4,6 +4,13 @@ iD.ui.preset.address = function(field, context) {
|
||||
entity,
|
||||
isInitialized;
|
||||
|
||||
var widths = {
|
||||
housenumber: 1/3,
|
||||
street: 2/3,
|
||||
city: 2/3,
|
||||
postcode: 1/3
|
||||
};
|
||||
|
||||
function getStreets() {
|
||||
var extent = entity.extent(context.graph()),
|
||||
l = extent.center(),
|
||||
@@ -103,18 +110,33 @@ iD.ui.preset.address = function(field, context) {
|
||||
return a && a.countryCodes && _.contains(a.countryCodes, countryCode);
|
||||
}) || _.first(iD.data.addressFormats);
|
||||
|
||||
function row(row) {
|
||||
// Normalize widths.
|
||||
var total = _.reduce(row, function(sum, field) {
|
||||
return sum + (widths[field] || .5);
|
||||
}, 0);
|
||||
|
||||
return row.map(function (field) {
|
||||
return {
|
||||
id: field,
|
||||
width: (widths[field] || .5) / total
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
enter.selectAll('div')
|
||||
.data(addressFormat.format)
|
||||
.enter()
|
||||
.append('div')
|
||||
.attr('class', 'addr-row')
|
||||
.selectAll('input')
|
||||
.data(function (d) { return d; })
|
||||
.data(row)
|
||||
.enter()
|
||||
.append('input')
|
||||
.property('type', 'text')
|
||||
.attr('placeholder', function (d) { return field.t('placeholders.' + d); })
|
||||
.attr('class', function (d) { return 'addr-' + d; });
|
||||
.attr('placeholder', function (d) { return field.t('placeholders.' + d.id); })
|
||||
.attr('class', function (d) { return 'addr-' + d.id; })
|
||||
.style('width', function (d) { return d.width * 100 + '%'; });
|
||||
|
||||
// Update
|
||||
|
||||
@@ -150,7 +172,7 @@ iD.ui.preset.address = function(field, context) {
|
||||
|
||||
wrap.selectAll('input')
|
||||
.each(function (field) {
|
||||
tags['addr:' + field] = this.value || undefined;
|
||||
tags['addr:' + field.id] = this.value || undefined;
|
||||
});
|
||||
|
||||
event.change(tags);
|
||||
@@ -159,7 +181,7 @@ iD.ui.preset.address = function(field, context) {
|
||||
function updateTags(tags) {
|
||||
wrap.selectAll('input')
|
||||
.value(function (field) {
|
||||
return tags['addr:' + field] || '';
|
||||
return tags['addr:' + field.id] || '';
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+58
-1
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @license
|
||||
* Lo-Dash 2.3.0 (Custom Build) <http://lodash.com/>
|
||||
* Build: `lodash --debug --output js/lib/lodash.js include="any,assign,bind,clone,compact,contains,debounce,difference,each,every,extend,filter,find,first,forEach,groupBy,indexOf,intersection,isEmpty,isEqual,isFunction,keys,last,map,omit,pairs,pluck,reject,some,throttle,union,uniq,unique,values,without,flatten,value,chain,cloneDeep,merge,pick" exports="global,node"`
|
||||
* Build: `lodash --debug --output js/lib/lodash.js include="any,assign,bind,clone,compact,contains,debounce,difference,each,every,extend,filter,find,first,forEach,groupBy,indexOf,intersection,isEmpty,isEqual,isFunction,keys,last,map,omit,pairs,pluck,reject,some,throttle,union,uniq,unique,values,without,flatten,value,chain,cloneDeep,merge,pick,reduce" exports="global,node"`
|
||||
* Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>
|
||||
* Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE>
|
||||
* Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||||
@@ -2784,6 +2784,60 @@
|
||||
*/
|
||||
var pluck = map;
|
||||
|
||||
/**
|
||||
* Reduces a collection to a value which is the accumulated result of running
|
||||
* each element in the collection through the callback, where each successive
|
||||
* callback execution consumes the return value of the previous execution. If
|
||||
* `accumulator` is not provided the first element of the collection will be
|
||||
* used as the initial `accumulator` value. The callback is bound to `thisArg`
|
||||
* and invoked with four arguments; (accumulator, value, index|key, collection).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @alias foldl, inject
|
||||
* @category Collections
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function} [callback=identity] The function called per iteration.
|
||||
* @param {*} [accumulator] Initial value of the accumulator.
|
||||
* @param {*} [thisArg] The `this` binding of `callback`.
|
||||
* @returns {*} Returns the accumulated value.
|
||||
* @example
|
||||
*
|
||||
* var sum = _.reduce([1, 2, 3], function(sum, num) {
|
||||
* return sum + num;
|
||||
* });
|
||||
* // => 6
|
||||
*
|
||||
* var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key) {
|
||||
* result[key] = num * 3;
|
||||
* return result;
|
||||
* }, {});
|
||||
* // => { 'a': 3, 'b': 6, 'c': 9 }
|
||||
*/
|
||||
function reduce(collection, callback, accumulator, thisArg) {
|
||||
var noaccum = arguments.length < 3;
|
||||
callback = lodash.createCallback(callback, thisArg, 4);
|
||||
|
||||
if (isArray(collection)) {
|
||||
var index = -1,
|
||||
length = collection.length;
|
||||
|
||||
if (noaccum) {
|
||||
accumulator = collection[++index];
|
||||
}
|
||||
while (++index < length) {
|
||||
accumulator = callback(accumulator, collection[index], index, collection);
|
||||
}
|
||||
} else {
|
||||
baseEach(collection, function(value, index, collection) {
|
||||
accumulator = noaccum
|
||||
? (noaccum = false, value)
|
||||
: callback(accumulator, value, index, collection)
|
||||
});
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
/**
|
||||
* The opposite of `_.filter` this method returns the elements of a
|
||||
* collection that the callback does **not** return truey for.
|
||||
@@ -3921,6 +3975,7 @@
|
||||
lodash.isString = isString;
|
||||
lodash.mixin = mixin;
|
||||
lodash.noop = noop;
|
||||
lodash.reduce = reduce;
|
||||
lodash.some = some;
|
||||
lodash.sortedIndex = sortedIndex;
|
||||
|
||||
@@ -3929,7 +3984,9 @@
|
||||
lodash.any = some;
|
||||
lodash.detect = find;
|
||||
lodash.findWhere = find;
|
||||
lodash.foldl = reduce;
|
||||
lodash.include = contains;
|
||||
lodash.inject = reduce;
|
||||
|
||||
forOwn(lodash, function(func, methodName) {
|
||||
if (!lodash.prototype[methodName]) {
|
||||
|
||||
Reference in New Issue
Block a user