mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-31 20:21:36 +02:00
Merge branch 'master' into validation
# Conflicts: # data/core.yaml # dist/locales/en.json # modules/ui/commit_warnings.js # modules/ui/entity_editor.js # modules/util/index.js # modules/util/util.js # modules/validations/index.js # modules/validations/many_deletions.js # modules/validations/missing_tag.js
This commit is contained in:
+22
-16
@@ -9,7 +9,8 @@ export function utilDetect(force) {
|
||||
detected = {};
|
||||
|
||||
var ua = navigator.userAgent,
|
||||
m = null;
|
||||
m = null,
|
||||
q = utilStringQs(window.location.hash.substring(1));
|
||||
|
||||
m = ua.match(/(edge)\/?\s*(\.?\d+(\.\d+)*)/i); // Edge
|
||||
if (m !== null) {
|
||||
@@ -59,24 +60,30 @@ export function utilDetect(force) {
|
||||
// Added due to incomplete svg style support. See #715
|
||||
detected.opera = (detected.browser.toLowerCase() === 'opera' && parseFloat(detected.version) < 15 );
|
||||
|
||||
detected.locale = (navigator.language || navigator.userLanguage || 'en-US');
|
||||
detected.language = detected.locale.split('-')[0];
|
||||
// Set locale based on url param (format 'en-US') or browser lang (default)
|
||||
if (q.hasOwnProperty('locale')) {
|
||||
detected.locale = q.locale;
|
||||
detected.language = q.locale.split('-')[0];
|
||||
} else {
|
||||
detected.locale = (navigator.language || navigator.userLanguage || 'en-US');
|
||||
detected.language = detected.locale.split('-')[0];
|
||||
|
||||
// Search `navigator.languages` for a better locale.. Prefer the first language,
|
||||
// unless the second language is a culture-specific version of the first one, see #3842
|
||||
if (navigator.languages && navigator.languages.length > 0) {
|
||||
var code0 = navigator.languages[0],
|
||||
parts0 = code0.split('-');
|
||||
// Search `navigator.languages` for a better locale. Prefer the first language,
|
||||
// unless the second language is a culture-specific version of the first one, see #3842
|
||||
if (navigator.languages && navigator.languages.length > 0) {
|
||||
var code0 = navigator.languages[0],
|
||||
parts0 = code0.split('-');
|
||||
|
||||
detected.locale = code0;
|
||||
detected.language = parts0[0];
|
||||
detected.locale = code0;
|
||||
detected.language = parts0[0];
|
||||
|
||||
if (navigator.languages.length > 1 && parts0.length === 1) {
|
||||
var code1 = navigator.languages[1],
|
||||
parts1 = code1.split('-');
|
||||
if (navigator.languages.length > 1 && parts0.length === 1) {
|
||||
var code1 = navigator.languages[1],
|
||||
parts1 = code1.split('-');
|
||||
|
||||
if (parts1[0] === parts0[0]) {
|
||||
detected.locale = code1;
|
||||
if (parts1[0] === parts0[0]) {
|
||||
detected.locale = code1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +97,6 @@ export function utilDetect(force) {
|
||||
}
|
||||
|
||||
// detect text direction
|
||||
var q = utilStringQs(window.location.hash.substring(1));
|
||||
var lang = dataLocales[detected.locale];
|
||||
if ((lang && lang.rtl) || (q.rtl === 'true')) {
|
||||
detected.textDirection = 'rtl';
|
||||
|
||||
@@ -5,6 +5,7 @@ export { utilDisplayName } from './util';
|
||||
export { utilDisplayNameForPath } from './util';
|
||||
export { utilDisplayType } from './util';
|
||||
export { utilDisplayLabel } from './util';
|
||||
export { utilEntityRoot } from './util';
|
||||
export { utilEditDistance } from './util';
|
||||
export { utilEntitySelector } from './util';
|
||||
export { utilEntityOrMemberSelector } from './util';
|
||||
@@ -28,7 +29,6 @@ export { utilRebind } from './rebind';
|
||||
export { utilSetTransform } from './util';
|
||||
export { utilSessionMutex } from './session_mutex';
|
||||
export { utilStringQs } from './util';
|
||||
// export { utilSuggestNames } from './suggest_names';
|
||||
export { utilTagText } from './util';
|
||||
export { utilTiler } from './tiler';
|
||||
export { utilTriggerEvent } from './trigger_event';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import _isFunction from 'lodash-es/isFunction';
|
||||
import _uniq from 'lodash-es/uniq';
|
||||
|
||||
import {
|
||||
event as d3_event,
|
||||
@@ -125,7 +126,7 @@ export function utilKeybinding(namespace) {
|
||||
|
||||
// Remove one or more keycode bindings.
|
||||
keybinding.off = function(codes, capture) {
|
||||
var arr = [].concat(codes);
|
||||
var arr = _uniq([].concat(codes));
|
||||
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var id = arr[i] + (capture ? '-capture' : '-bubble');
|
||||
@@ -141,7 +142,7 @@ export function utilKeybinding(namespace) {
|
||||
return keybinding.off(codes, capture);
|
||||
}
|
||||
|
||||
var arr = [].concat(codes);
|
||||
var arr = _uniq([].concat(codes));
|
||||
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var id = arr[i] + (capture ? '-capture' : '-bubble');
|
||||
|
||||
@@ -42,7 +42,9 @@ export function t(s, o, loc) {
|
||||
if (rep !== undefined) {
|
||||
if (o) {
|
||||
for (var k in o) {
|
||||
rep = rep.replace('{' + k + '}', o[k]);
|
||||
var variable = '{' + k + '}';
|
||||
var re = new RegExp(variable, 'g'); // check globally for variables
|
||||
rep = rep.replace(re, o[k]);
|
||||
}
|
||||
}
|
||||
return rep;
|
||||
|
||||
+50
-32
@@ -37,6 +37,7 @@ export function utilEntityOrMemberSelector(ids, graph) {
|
||||
export function utilEntityOrDeepMemberSelector(ids, graph) {
|
||||
var seen = {};
|
||||
var allIDs = [];
|
||||
|
||||
function addEntityAndMembersIfNotYetSeen(id) {
|
||||
// avoid infinite recursion for circular relations by skipping seen entities
|
||||
if (seen[id]) return;
|
||||
@@ -53,6 +54,7 @@ export function utilEntityOrDeepMemberSelector(ids, graph) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ids.forEach(function(id) {
|
||||
addEntityAndMembersIfNotYetSeen(id);
|
||||
});
|
||||
@@ -85,9 +87,9 @@ export function utilGetAllNodes(ids, graph) {
|
||||
|
||||
|
||||
export function utilDisplayName(entity) {
|
||||
var localizedNameKey = 'name:' + utilDetect().locale.toLowerCase().split('-')[0],
|
||||
name = entity.tags[localizedNameKey] || entity.tags.name || '',
|
||||
network = entity.tags.cycle_network || entity.tags.network;
|
||||
var localizedNameKey = 'name:' + utilDetect().locale.toLowerCase().split('-')[0];
|
||||
var name = entity.tags[localizedNameKey] || entity.tags.name || '';
|
||||
var network = entity.tags.cycle_network || entity.tags.network;
|
||||
|
||||
if (!name && entity.tags.ref) {
|
||||
name = entity.tags.ref;
|
||||
@@ -137,6 +139,15 @@ export function utilDisplayLabel(entity, context) {
|
||||
}
|
||||
|
||||
|
||||
export function utilEntityRoot(entityType) {
|
||||
return {
|
||||
node: 'n',
|
||||
way: 'w',
|
||||
relation: 'r'
|
||||
}[entityType];
|
||||
}
|
||||
|
||||
|
||||
export function utilStringQs(str) {
|
||||
return str.split('&').reduce(function(obj, pair){
|
||||
var parts = pair.split('=');
|
||||
@@ -152,11 +163,12 @@ export function utilStringQs(str) {
|
||||
|
||||
|
||||
export function utilQsString(obj, noencode) {
|
||||
// encode everything except special characters used in certain hash parameters:
|
||||
// "/" in map states, ":", ",", {" and "}" in background
|
||||
function softEncode(s) {
|
||||
// encode everything except special characters used in certain hash parameters:
|
||||
// "/" in map states, ":", ",", {" and "}" in background
|
||||
return encodeURIComponent(s).replace(/(%2F|%3A|%2C|%7B|%7D)/g, decodeURIComponent);
|
||||
return encodeURIComponent(s).replace(/(%2F|%3A|%2C|%7B|%7D)/g, decodeURIComponent);
|
||||
}
|
||||
|
||||
return Object.keys(obj).sort().map(function(key) {
|
||||
return encodeURIComponent(key) + '=' + (
|
||||
noencode ? softEncode(obj[key]) : encodeURIComponent(obj[key]));
|
||||
@@ -165,36 +177,41 @@ export function utilQsString(obj, noencode) {
|
||||
|
||||
|
||||
export function utilPrefixDOMProperty(property) {
|
||||
var prefixes = ['webkit', 'ms', 'moz', 'o'],
|
||||
i = -1,
|
||||
n = prefixes.length,
|
||||
s = document.body;
|
||||
var prefixes = ['webkit', 'ms', 'moz', 'o'];
|
||||
var i = -1;
|
||||
var n = prefixes.length;
|
||||
var s = document.body;
|
||||
|
||||
if (property in s)
|
||||
return property;
|
||||
|
||||
property = property.substr(0, 1).toUpperCase() + property.substr(1);
|
||||
|
||||
while (++i < n)
|
||||
if (prefixes[i] + property in s)
|
||||
while (++i < n) {
|
||||
if (prefixes[i] + property in s) {
|
||||
return prefixes[i] + property;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
export function utilPrefixCSSProperty(property) {
|
||||
var prefixes = ['webkit', 'ms', 'Moz', 'O'],
|
||||
i = -1,
|
||||
n = prefixes.length,
|
||||
s = document.body.style;
|
||||
var prefixes = ['webkit', 'ms', 'Moz', 'O'];
|
||||
var i = -1;
|
||||
var n = prefixes.length;
|
||||
var s = document.body.style;
|
||||
|
||||
if (property.toLowerCase() in s)
|
||||
if (property.toLowerCase() in s) {
|
||||
return property.toLowerCase();
|
||||
}
|
||||
|
||||
while (++i < n)
|
||||
if (prefixes[i] + property in s)
|
||||
while (++i < n) {
|
||||
if (prefixes[i] + property in s) {
|
||||
return '-' + prefixes[i].toLowerCase() + property.replace(/([A-Z])/g, '-$1').toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -202,10 +219,9 @@ export function utilPrefixCSSProperty(property) {
|
||||
|
||||
var transformProperty;
|
||||
export function utilSetTransform(el, x, y, scale) {
|
||||
var prop = transformProperty = transformProperty || utilPrefixCSSProperty('Transform'),
|
||||
translate = utilDetect().opera ?
|
||||
'translate(' + x + 'px,' + y + 'px)' :
|
||||
'translate3d(' + x + 'px,' + y + 'px,0)';
|
||||
var prop = transformProperty = transformProperty || utilPrefixCSSProperty('Transform');
|
||||
var translate = utilDetect().opera ? 'translate(' + x + 'px,' + y + 'px)'
|
||||
: 'translate3d(' + x + 'px,' + y + 'px,0)';
|
||||
return el.style(prop, translate + (scale ? ' scale(' + scale + ')' : ''));
|
||||
}
|
||||
|
||||
@@ -240,11 +256,12 @@ export function utilEditDistance(a, b) {
|
||||
// 1. Only works on HTML elements, not SVG
|
||||
// 2. Does not cause style recalculation
|
||||
export function utilFastMouse(container) {
|
||||
var rect = container.getBoundingClientRect(),
|
||||
rectLeft = rect.left,
|
||||
rectTop = rect.top,
|
||||
clientLeft = +container.clientLeft,
|
||||
clientTop = +container.clientTop;
|
||||
var rect = container.getBoundingClientRect();
|
||||
var rectLeft = rect.left;
|
||||
var rectTop = rect.top;
|
||||
var clientLeft = +container.clientLeft;
|
||||
var clientTop = +container.clientTop;
|
||||
|
||||
if (textDirection === 'rtl') {
|
||||
rectLeft = 0;
|
||||
}
|
||||
@@ -262,9 +279,9 @@ export var utilGetPrototypeOf = Object.getPrototypeOf || function(obj) { return
|
||||
|
||||
|
||||
export function utilAsyncMap(inputs, func, callback) {
|
||||
var remaining = inputs.length,
|
||||
results = [],
|
||||
errors = [];
|
||||
var remaining = inputs.length;
|
||||
var results = [];
|
||||
var errors = [];
|
||||
|
||||
inputs.forEach(function(d, i) {
|
||||
func(d, function done(err, data) {
|
||||
@@ -279,8 +296,9 @@ export function utilAsyncMap(inputs, func, callback) {
|
||||
|
||||
// wraps an index to an interval [0..length-1]
|
||||
export function utilWrap(index, length) {
|
||||
if (index < 0)
|
||||
if (index < 0) {
|
||||
index += Math.ceil(-index/length)*length;
|
||||
}
|
||||
return index % length;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user