Remove continued iD references (#3341)

* Remove continued iD references

* make build.js safe enough to dodge json plugin bug

* Package as an iife to avoid var name issue
This commit is contained in:
Tom MacWright
2016-08-10 20:06:45 -07:00
committed by GitHub
parent 6341d4e4b5
commit 8819d3d061
23 changed files with 92 additions and 54 deletions
+1 -1
View File
@@ -50,7 +50,7 @@
"no-shadow": "off",
"no-shadow-restricted-names": "error",
"no-throw-literal": "error",
"no-undef": "warn", // To catch uses of iD global - TODO remove
"no-undef": "error",
"no-unneeded-ternary": "error",
"no-unused-expressions": "error",
"no-unexpected-multiline": "error",
+3 -3
View File
@@ -96,8 +96,8 @@ function suggestionsToPresets(presets) {
delete existing[name];
}
if (!existing[name]) {
tags = _.extend({name: name}, suggestions[key][value][name].tags);
addSuggestion(item, tags, name, count);
tags = _.extend({name: name.replace(/"/g, '')}, suggestions[key][value][name].tags);
addSuggestion(item, tags, name.replace(/"/g, ''), count);
}
}
}
@@ -112,7 +112,7 @@ function suggestionsToPresets(presets) {
return;
}
presets[category] = {
presets[category.replace(/"/g, '')] = {
tags: parent.tags ? _.merge(tags, parent.tags) : tags,
name: name,
icon: parent.icon,
+1 -1
View File
@@ -66267,4 +66267,4 @@
],
"suggestion": true
}
}
}
+4 -2
View File
@@ -1,4 +1,6 @@
import _ from 'lodash';
import { deprecated } from '../../data/index';
export function DeprecateTags(entityId) {
return function(graph) {
var entity = graph.entity(entityId),
@@ -7,9 +9,9 @@ export function DeprecateTags(entityId) {
rule;
// This handles deprecated tags with a single condition
for (var i = 0; i < iD.data.deprecated.length; i++) {
for (var i = 0; i < deprecated.length; i++) {
rule = iD.data.deprecated[i];
rule = deprecated[i];
var match = _.toPairs(rule.old)[0],
replacements = rule.replace ? _.toPairs(rule.replace) : null;
+3 -1
View File
@@ -1,4 +1,6 @@
import _ from 'lodash';
import { discarded } from '../../data/index';
export function DiscardTags(difference) {
return function(graph) {
function discardTags(entity) {
@@ -9,7 +11,7 @@ export function DiscardTags(difference) {
});
graph = graph.replace(entity.update({
tags: _.omit(tags, iD.data.discarded)
tags: _.omit(tags, discarded)
}));
}
}
+2 -1
View File
@@ -3,6 +3,7 @@ import _ from 'lodash';
import { DeleteMultiple } from './delete_multiple';
import { Entity } from '../core/index';
import { diff3_merge } from '../util/diff3';
import { discarded } from '../../data/index';
export function MergeRemoteChanges(id, localGraph, remoteGraph, formatUser) {
var option = 'safe', // 'safe', 'force_local', 'force_remote'
@@ -149,7 +150,7 @@ export function MergeRemoteChanges(id, localGraph, remoteGraph, formatUser) {
function mergeTags(base, remote, target) {
function ignoreKey(k) {
return _.includes(iD.data.discarded, k);
return _.includes(discarded, k);
}
if (option === 'force_local' || _.isEqual(target.tags, remote.tags)) {
+8 -5
View File
@@ -6,9 +6,12 @@ import { Detect } from '../util/detect';
import { Features } from '../renderer/features';
import { History } from './history';
import { Map } from '../renderer/map';
import { Select } from '../modes/select';
import { RawMercator } from '../geo/raw_mercator';
import { presets as presetsInit } from '../presets/presets';
import { init as uiInit } from '../ui/init';
import { locales, en } from '../../data/index';
import * as services from '../services/index';
export var areaKeys = {};
@@ -18,7 +21,7 @@ export function Context(root) {
current: function(_) { this._current = _; }
};
}
addTranslation('en', iD.data.en);
addTranslation('en', en);
setLocale('en');
var dispatch = d3.dispatch('enter', 'exit', 'change'),
@@ -97,7 +100,7 @@ export function Context(root) {
if (!context.hasEntity(id)) return;
map.on('drawn.zoomToEntity', null);
context.on('enter.zoomToEntity', null);
context.enter(iD.modes.Select(context, [id]));
context.enter(Select(context, [id]));
});
context.on('enter.zoomToEntity', function() {
@@ -136,7 +139,7 @@ export function Context(root) {
connection.flush();
features.reset();
history.reset();
_.each(iD.services, function(service) {
_.each(services, function(service) {
var reset = service().reset;
if (reset) reset(context);
});
@@ -330,7 +333,7 @@ export function Context(root) {
};
context.loadLocale = function(cb) {
if (locale && locale !== 'en' && iD.data.locales.indexOf(locale) !== -1) {
if (locale && locale !== 'en' && locales.indexOf(locale) !== -1) {
localePath = localePath || context.asset('locales/' + locale + '.json');
d3.json(localePath, function(err, result) {
addTranslation(locale, result);
@@ -349,7 +352,7 @@ export function Context(root) {
context.projection = RawMercator();
locale = Detect().locale;
if (locale && iD.data.locales.indexOf(locale) === -1) {
if (locale && locales.indexOf(locale) === -1) {
locale = locale.split('-')[0];
}
+4 -2
View File
@@ -1,5 +1,7 @@
import _ from 'lodash';
import { debug } from '../index';
import { interestingTag } from './tags';
import { deprecated as deprecatedData } from '../../data/index';
export function Entity(attrs) {
// For prototypal inheritance.
@@ -63,7 +65,7 @@ Entity.prototype = {
this.visible = true;
}
if (iD.debug) {
if (debug) {
Object.freeze(this);
Object.freeze(this.tags);
@@ -134,7 +136,7 @@ Entity.prototype = {
var tags = _.toPairs(this.tags);
var deprecated = {};
iD.data.deprecated.forEach(function(d) {
deprecatedData.forEach(function(d) {
var match = _.toPairs(d.old)[0];
tags.forEach(function(t) {
if (t[0] === match[0] &&
+2 -1
View File
@@ -1,5 +1,6 @@
import _ from 'lodash';
import { getPrototypeOf } from '../util/index';
import { debug } from '../index';
export function Graph(other, mutable) {
if (!(this instanceof Graph)) return new Graph(other, mutable);
@@ -92,7 +93,7 @@ Graph.prototype = {
nodes[i] = this.entity(entity.nodes[i]);
}
if (iD.debug) Object.freeze(nodes);
if (debug) Object.freeze(nodes);
this._childNodes[entity.id] = nodes;
return this._childNodes[entity.id];
+2
View File
@@ -35,6 +35,8 @@ export { TileLayer } from './renderer/tile_layer';
import * as data from '../data/index.js';
export var debug = false;
export {
data,
actions,
+1 -2
View File
@@ -21,7 +21,7 @@ var taginfo = {},
vertex: 'nodes',
area: 'ways',
line: 'ways'
};
},
tag_members_fractions = {
point: 'count_node_members_fraction',
vertex: 'count_node_members_fraction',
@@ -30,7 +30,6 @@ var taginfo = {},
relation: 'count_relation_members_fraction'
};
function sets(parameters, n, o) {
if (parameters.geometry && o[parameters.geometry]) {
parameters[n] = o[parameters.geometry];
+8 -3
View File
@@ -1,4 +1,9 @@
import { polygonIntersectsPolygon } from '../geo/index';
import {
imperial as imperialData,
driveLeft as driveLeftData,
imagery as imageryData
} from '../../data/index';
export function Debug(projection, context) {
@@ -74,7 +79,7 @@ export function Debug(projection, context) {
var extent = context.map().extent(),
availableImagery = showsImagery && multipolygons(iD.data.imagery.filter(function(source) {
availableImagery = showsImagery && multipolygons(imageryData.filter(function(source) {
if (!source.polygon) return false;
return source.polygon.some(function(polygon) {
return polygonIntersectsPolygon(polygon, extent, true);
@@ -94,7 +99,7 @@ export function Debug(projection, context) {
var imperial = layer
.selectAll('path.debug-imperial')
.data(showsImperial ? [iD.data.imperial] : []);
.data(showsImperial ? [imperialData] : []);
imperial.enter()
.append('path')
@@ -106,7 +111,7 @@ export function Debug(projection, context) {
var driveLeft = layer
.selectAll('path.debug-drive-left')
.data(showsDriveLeft ? [iD.data.driveLeft] : []);
.data(showsDriveLeft ? [driveLeftData] : []);
driveLeft.enter()
.append('path')
+4 -3
View File
@@ -1,5 +1,6 @@
import _ from 'lodash';
import { PointTransform } from './point_transform';
import { mapillary as mapillaryService } from '../services/index';
export function MapillaryImages(projection, context, dispatch) {
var debouncedRedraw = _.debounce(function () { dispatch.change(); }, 1000),
@@ -15,10 +16,10 @@ export function MapillaryImages(projection, context, dispatch) {
}
function getMapillary() {
if (iD.services.mapillary && !_mapillary) {
_mapillary = iD.services.mapillary.init();
if (mapillaryService && !_mapillary) {
_mapillary = mapillaryService.init();
_mapillary.event.on('loadedImages', debouncedRedraw);
} else if (!iD.services.mapillary && _mapillary) {
} else if (!mapillaryService && _mapillary) {
_mapillary = null;
}
+4 -3
View File
@@ -1,5 +1,6 @@
import _ from 'lodash';
import { PointTransform } from './point_transform';
import { mapillary as mapillaryService } from '../services/index';
export function MapillarySigns(projection, context, dispatch) {
var debouncedRedraw = _.debounce(function () { dispatch.change(); }, 1000),
@@ -14,10 +15,10 @@ export function MapillarySigns(projection, context, dispatch) {
}
function getMapillary() {
if (iD.services.mapillary && !_mapillary) {
_mapillary = iD.services.mapillary.init();
if (mapillaryService && !_mapillary) {
_mapillary = mapillaryService.init();
_mapillary.event.on('loadedSigns', debouncedRedraw);
} else if (!iD.services.mapillary && _mapillary) {
} else if (!mapillaryService && _mapillary) {
_mapillary = null;
}
return _mapillary;
+4 -2
View File
@@ -1,3 +1,5 @@
import { pavedTags } from '../core/tags';
export function TagClasses() {
var primaries = [
'building', 'highway', 'railway', 'waterway', 'aeroway',
@@ -85,8 +87,8 @@ export function TagClasses() {
var paved = (t.highway !== 'track');
for (k in t) {
v = t[k];
if (k in iD.pavedTags) {
paved = !!iD.pavedTags[k][v];
if (k in pavedTags) {
paved = !!pavedTags[k][v];
break;
}
}
+6 -4
View File
@@ -1,5 +1,7 @@
import _ from 'lodash';
import { Extent, chooseEdge, sphericalDistance } from '../../geo/index';
import { nominatim } from '../../services/index';
import { addressFormats } from '../../../data/index';
export function address(field, context) {
var dispatch = d3.dispatch('init', 'change'),
@@ -111,11 +113,11 @@ export function address(field, context) {
var center = entity.extent(context.graph()).center(),
addressFormat;
iD.services.nominatim.init();
iD.services.nominatim.countryCode(center, function (err, countryCode) {
addressFormat = _.find(iD.data.addressFormats, function (a) {
nominatim.init();
nominatim.countryCode(center, function (err, countryCode) {
addressFormat = _.find(addressFormats, function (a) {
return a && a.countryCodes && _.includes(a.countryCodes, countryCode);
}) || _.first(iD.data.addressFormats);
}) || _.first(addressFormats);
function row(r) {
// Normalize widths.
+5 -3
View File
@@ -1,6 +1,8 @@
import { t } from '../../util/locale';
import _ from 'lodash';
import { t } from '../../util/locale';
import { nominatim } from '../../services/index';
export {
combo as typeCombo,
combo as multiCombo,
@@ -240,8 +242,8 @@ export function combo(field, context) {
if (isNetwork) {
var center = entity.extent(context.graph()).center();
iD.services.nominatim.init();
iD.services.nominatim.countryCode(center, function (err, code) {
nominatim.init();
nominatim.countryCode(center, function (err, code) {
countryCode = code;
});
}
+6 -4
View File
@@ -1,4 +1,6 @@
import { t } from '../../util/locale';
import { nominatim as nominatimService } from '../../services/index';
import { phoneFormats } from '../../../data/index';
export {
url as text,
@@ -30,11 +32,11 @@ export function url(field, context) {
if (field.type === 'tel') {
var center = entity.extent(context.graph()).center();
iD.services.nominatim.init();
iD.services.nominatim.countryCode(center, function (err, countryCode) {
if (err || !iD.data.phoneFormats[countryCode]) return;
nominatimService.init();
nominatimService.countryCode(center, function (err, countryCode) {
if (err || !phoneFormats[countryCode]) return;
selection.selectAll('#' + fieldId)
.attr('placeholder', iD.data.phoneFormats[countryCode]);
.attr('placeholder', phoneFormats[countryCode]);
});
} else if (field.type === 'number') {
+7 -5
View File
@@ -4,10 +4,12 @@ import _ from 'lodash';
import { Detect } from '../../util/detect';
import { Icon } from '../../svg/index';
import { SuggestNames } from '../../util/index';
import { wikipedia as wikipediaService } from '../../services/index';
import { suggestions, wikipedia as wikipediaData } from '../../../data/index';
export function localized(field, context) {
var dispatch = d3.dispatch('change', 'input'),
wikipedia = iD.services.wikipedia.init(),
wikipedia = wikipediaService.init(),
input, localizedInputs, wikiTitles,
entity;
@@ -24,7 +26,7 @@ export function localized(field, context) {
if (field.id === 'name') {
var preset = context.presets().match(entity, context.graph());
input.call(d3.combobox().fetcher(
SuggestNames(preset, iD.data.suggestions)
SuggestNames(preset, suggestions)
));
}
@@ -81,7 +83,7 @@ export function localized(field, context) {
function changeLang(d) {
var lang = d3.select(this).value(),
t = {},
language = _.find(iD.data.wikipedia, function(d) {
language = _.find(wikipediaData, function(d) {
return d[0].toLowerCase() === lang.toLowerCase() ||
d[1].toLowerCase() === lang.toLowerCase();
});
@@ -116,7 +118,7 @@ export function localized(field, context) {
function fetcher(value, cb) {
var v = value.toLowerCase();
cb(iD.data.wikipedia.filter(function(d) {
cb(wikipediaData.filter(function(d) {
return d[0].toLowerCase().indexOf(v) >= 0 ||
d[1].toLowerCase().indexOf(v) >= 0 ||
d[2].toLowerCase().indexOf(v) >= 0;
@@ -202,7 +204,7 @@ export function localized(field, context) {
entry.select('.localized-lang')
.value(function(d) {
var lang = _.find(iD.data.wikipedia, function(lang) { return lang[2] === d.lang; });
var lang = _.find(wikipediaData, function(lang) { return lang[2] === d.lang; });
return lang ? lang[1] : d.lang;
});
+2 -1
View File
@@ -1,5 +1,6 @@
import _ from 'lodash';
import { pointInPolygon } from '../../geo/index';
import { imperial as imperialData } from '../../../data/index';
export function maxspeed(field, context) {
var dispatch = d3.dispatch('change'),
@@ -32,7 +33,7 @@ export function maxspeed(field, context) {
var childNodes = context.graph().childNodes(context.entity(entity.id)),
loc = childNodes[~~(childNodes.length/2)].loc;
imperial = _.some(iD.data.imperial.features, function(f) {
imperial = _.some(imperialData.features, function(f) {
return _.some(f.geometry.coordinates, function(d) {
return pointInPolygon(loc, d);
});
+11 -6
View File
@@ -3,11 +3,16 @@ import _ from 'lodash';
import { ChangeTags } from '../../actions/index';
import { Detect } from '../../util/detect';
import { Icon } from '../../svg/index';
import { wikipedia as wikipediaData } from '../../../data/index';
import {
wikipedia as wikipediaService,
wikidata as wikidataService
} from '../../services/index';
export function wikipedia(field, context) {
var dispatch = d3.dispatch('change'),
wikipedia = iD.services.wikipedia.init(),
wikidata = iD.services.wikidata.init(),
wikipedia = wikipediaService.init(),
wikidata = wikidataService.init(),
link, entity, lang, title;
function wiki(selection) {
@@ -15,7 +20,7 @@ export function wikipedia(field, context) {
.fetcher(function(value, cb) {
var v = value.toLowerCase();
cb(iD.data.wikipedia.filter(function(d) {
cb(wikipediaData.filter(function(d) {
return d[0].toLowerCase().indexOf(v) >= 0 ||
d[1].toLowerCase().indexOf(v) >= 0 ||
d[2].toLowerCase().indexOf(v) >= 0;
@@ -78,7 +83,7 @@ export function wikipedia(field, context) {
var value = lang.value().toLowerCase();
var locale = Detect().locale.toLowerCase();
var localeLanguage;
return _.find(iD.data.wikipedia, function(d) {
return _.find(wikipediaData, function(d) {
if (d[2] === locale) localeLanguage = d;
return d[0].toLowerCase() === value ||
d[1].toLowerCase() === value ||
@@ -98,7 +103,7 @@ export function wikipedia(field, context) {
function change(skipWikidata) {
var value = title.value(),
m = value.match(/https?:\/\/([-a-z]+)\.wikipedia\.org\/(?:wiki|\1-[-a-z]+)\/([^#]+)(?:#(.+))?/),
l = m && _.find(iD.data.wikipedia, function(d) { return m[1] === d[2]; }),
l = m && _.find(wikipediaData, function(d) { return m[1] === d[2]; }),
anchor,
syncTags = {};
@@ -162,7 +167,7 @@ export function wikipedia(field, context) {
wiki.tags = function(tags) {
var value = tags[field.key] || '',
m = value.match(/([^:]+):([^#]+)(?:#(.+))?/),
l = m && _.find(iD.data.wikipedia, function(d) { return m[1] === d[2]; }),
l = m && _.find(wikipediaData, function(d) { return m[1] === d[2]; }),
anchor = m && m[3];
// value in correct format
+3 -1
View File
@@ -1,4 +1,6 @@
import { Icon } from '../svg/index';
import { featureIcons } from '../../data/index';
export function PresetIcon() {
var preset, geometry;
@@ -11,7 +13,7 @@ export function PresetIcon() {
p = preset.apply(this, arguments),
geom = geometry.apply(this, arguments),
icon = p.icon || (geom === 'line' ? 'other-line' : 'marker-stroked'),
maki = iD.data.featureIcons.hasOwnProperty(icon + '-24');
maki = featureIcons.hasOwnProperty(icon + '-24');
if (icon === 'dentist') maki = true; // workaround for dentist icon missing in `maki-sprite.json`
+1
View File
@@ -10,6 +10,7 @@
"scripts": {
"test": "npm run lint && make && phantomjs node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/index.html dot",
"start": "rollup --config=./rollup.config.js -w --input ./modules/id.js --output dist/iD.js",
"build": "rollup --config=./rollup.config.js -f iife --input ./modules/id.js --output dist/iD.js && uglifyjs dist/iD.js -c -m -o dist/iD.min.js",
"lint": "eslint js/id test/spec modules"
},
"repository": {