mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-30 08:50:32 +02:00
preset-input-wrap -> form-field-input-wrap
This better describes what it does. Also, took this opportunity to update a bunch of the uifield code (no multi line variable declarations, prefix state variables with _, eliminate unnecessray lodash, etc)
This commit is contained in:
@@ -1294,7 +1294,7 @@ a.hide-toggle {
|
||||
.form-field > input,
|
||||
.form-field > textarea,
|
||||
.form-field .localized-input-wrap > input,
|
||||
.form-field .preset-input-wrap {
|
||||
.form-field .form-field-input-wrap {
|
||||
border: 1px solid #ccc;
|
||||
min-height: 30px;
|
||||
border-top: 0;
|
||||
@@ -1336,7 +1336,7 @@ a.hide-toggle {
|
||||
/* Inspector (hover styles)
|
||||
------------------------------------------------------- */
|
||||
.inspector-hover .checkselect label:last-of-type,
|
||||
.inspector-hover .preset-input-wrap .label,
|
||||
.inspector-hover .form-field-input-wrap .label,
|
||||
.inspector-hover .form-field-multicombo,
|
||||
.inspector-hover .structure-extras-wrap,
|
||||
.inspector-hover .comments-container .comment,
|
||||
@@ -1494,7 +1494,7 @@ a.hide-toggle {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.preset-input-wrap .label {
|
||||
.form-field-input-wrap .label {
|
||||
height: 30px;
|
||||
background: #F6F6F6;
|
||||
padding: 5px 10px;
|
||||
@@ -1504,19 +1504,19 @@ a.hide-toggle {
|
||||
/* Field - Access, Cycleway, Structure
|
||||
------------------------------------------------------- */
|
||||
.structure-extras-wrap li,
|
||||
.form-field-cycleway .preset-input-wrap li,
|
||||
.form-field-access .preset-input-wrap li {
|
||||
.form-field-cycleway .form-field-input-wrap li,
|
||||
.form-field-access .form-field-input-wrap li {
|
||||
border-bottom: 1px solid #ccc;
|
||||
display: flex;
|
||||
}
|
||||
.structure-extras-wrap li:last-child,
|
||||
.form-field-cycleway .preset-input-wrap li:last-child,
|
||||
.form-field-access .preset-input-wrap li:last-child {
|
||||
.form-field-cycleway .form-field-input-wrap li:last-child,
|
||||
.form-field-access .form-field-input-wrap li:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.structure-extras-wrap li > *,
|
||||
.form-field-cycleway .preset-input-wrap li > *,
|
||||
.form-field-access .preset-input-wrap li > * {
|
||||
.form-field-cycleway .form-field-input-wrap li > *,
|
||||
.form-field-access .form-field-input-wrap li > * {
|
||||
flex: 1;
|
||||
}
|
||||
.structure-input-type-wrap input,
|
||||
@@ -1547,7 +1547,7 @@ a.hide-toggle {
|
||||
border-right-width: 1px;
|
||||
}
|
||||
|
||||
.preset-input-wrap li:last-child input {
|
||||
.form-field-input-wrap li:last-child input {
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
|
||||
|
||||
@@ -176,8 +176,8 @@ export function uiFieldHelp(context, fieldName) {
|
||||
|
||||
|
||||
fieldHelp.body = function(selection) {
|
||||
// This control expects the field to have a preset-input-wrap div
|
||||
_wrap = selection.selectAll('.preset-input-wrap');
|
||||
// This control expects the field to have a form-field-input-wrap div
|
||||
_wrap = selection.selectAll('.form-field-input-wrap');
|
||||
if (_wrap.empty()) return;
|
||||
|
||||
// absolute position relative to the inspector, so it "floats" above the fields
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import _forEach from 'lodash-es/forEach';
|
||||
|
||||
import { dispatch as d3_dispatch } from 'd3-dispatch';
|
||||
import { select as d3_select } from 'd3-selection';
|
||||
import { d3combobox as d3_combobox } from '../../lib/d3.combobox.js';
|
||||
@@ -12,16 +10,16 @@ import {
|
||||
|
||||
|
||||
export function uiFieldAccess(field, context) {
|
||||
var dispatch = d3_dispatch('change'),
|
||||
items;
|
||||
var dispatch = d3_dispatch('change');
|
||||
var items = d3_select(null);
|
||||
|
||||
function access(selection) {
|
||||
var wrap = selection.selectAll('.preset-input-wrap')
|
||||
var wrap = selection.selectAll('.form-field-input-wrap')
|
||||
.data([0]);
|
||||
|
||||
wrap = wrap.enter()
|
||||
.append('div')
|
||||
.attr('class', 'preset-input-wrap')
|
||||
.attr('class', 'form-field-input-wrap')
|
||||
.append('ul')
|
||||
.merge(wrap);
|
||||
|
||||
@@ -215,9 +213,12 @@ export function uiFieldAccess(field, context) {
|
||||
items.selectAll('#preset-input-access-access')
|
||||
.attr('placeholder', 'yes');
|
||||
|
||||
_forEach(placeholders[tags.highway], function(v, k) {
|
||||
var which = tags.highway;
|
||||
var keys = Object.keys(placeholders[which]);
|
||||
keys.forEach(function(k) {
|
||||
var v = placeholders[which][k];
|
||||
items.selectAll('#preset-input-access-' + k)
|
||||
.attr('placeholder', function() { return (tags.access || v); });
|
||||
.attr('placeholder', tags.access || v);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -24,24 +24,26 @@ import {
|
||||
|
||||
|
||||
export function uiFieldAddress(field, context) {
|
||||
var dispatch = d3_dispatch('init', 'change'),
|
||||
nominatim = services.geocoder,
|
||||
wrap = d3_select(null),
|
||||
isInitialized = false,
|
||||
entity;
|
||||
var dispatch = d3_dispatch('init', 'change');
|
||||
var nominatim = services.geocoder;
|
||||
var wrap = d3_select(null);
|
||||
var _isInitialized = false;
|
||||
var _entity;
|
||||
|
||||
function getNearStreets() {
|
||||
var extent = entity.extent(context.graph()),
|
||||
l = extent.center(),
|
||||
box = geoExtent(l).padByMeters(200);
|
||||
var extent = _entity.extent(context.graph());
|
||||
var l = extent.center();
|
||||
var box = geoExtent(l).padByMeters(200);
|
||||
|
||||
var streets = context.intersects(box)
|
||||
.filter(isAddressable)
|
||||
.map(function(d) {
|
||||
var loc = context.projection([
|
||||
(extent[0][0] + extent[1][0]) / 2,
|
||||
(extent[0][1] + extent[1][1]) / 2]),
|
||||
choice = geoChooseEdge(context.childNodes(d), loc, context.projection);
|
||||
(extent[0][1] + extent[1][1]) / 2
|
||||
]);
|
||||
var choice = geoChooseEdge(context.childNodes(d), loc, context.projection);
|
||||
|
||||
return {
|
||||
title: d.tags.name,
|
||||
value: d.tags.name,
|
||||
@@ -61,9 +63,9 @@ export function uiFieldAddress(field, context) {
|
||||
|
||||
|
||||
function getNearCities() {
|
||||
var extent = entity.extent(context.graph()),
|
||||
l = extent.center(),
|
||||
box = geoExtent(l).padByMeters(200);
|
||||
var extent = _entity.extent(context.graph());
|
||||
var l = extent.center();
|
||||
var box = geoExtent(l).padByMeters(200);
|
||||
|
||||
var cities = context.intersects(box)
|
||||
.filter(isAddressable)
|
||||
@@ -99,14 +101,12 @@ export function uiFieldAddress(field, context) {
|
||||
}
|
||||
|
||||
function getNearValues(key) {
|
||||
var extent = entity.extent(context.graph()),
|
||||
l = extent.center(),
|
||||
box = geoExtent(l).padByMeters(200);
|
||||
var extent = _entity.extent(context.graph());
|
||||
var l = extent.center();
|
||||
var box = geoExtent(l).padByMeters(200);
|
||||
|
||||
var results = context.intersects(box)
|
||||
.filter(function hasTag(d) {
|
||||
return d.tags[key];
|
||||
})
|
||||
.filter(function hasTag(d) { return d.tags[key]; })
|
||||
.map(function(d) {
|
||||
return {
|
||||
title: d.tags[key],
|
||||
@@ -159,8 +159,8 @@ export function uiFieldAddress(field, context) {
|
||||
.append('input')
|
||||
.property('type', 'text')
|
||||
.attr('placeholder', function (d) {
|
||||
var localkey = d.id + '!' + countryCode.toLowerCase(),
|
||||
tkey = field.strings.placeholders[localkey] ? localkey : d.id;
|
||||
var localkey = d.id + '!' + countryCode.toLowerCase();
|
||||
var tkey = field.strings.placeholders[localkey] ? localkey : d.id;
|
||||
return field.t('placeholders.' + tkey);
|
||||
})
|
||||
.attr('class', function (d) { return 'addr-' + d.id; })
|
||||
@@ -200,23 +200,23 @@ export function uiFieldAddress(field, context) {
|
||||
.on('input', change(true));
|
||||
|
||||
dispatch.call('init');
|
||||
isInitialized = true;
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
|
||||
function address(selection) {
|
||||
isInitialized = false;
|
||||
_isInitialized = false;
|
||||
|
||||
wrap = selection.selectAll('.preset-input-wrap')
|
||||
wrap = selection.selectAll('.form-field-input-wrap')
|
||||
.data([0]);
|
||||
|
||||
wrap = wrap.enter()
|
||||
.append('div')
|
||||
.attr('class', 'preset-input-wrap')
|
||||
.attr('class', 'form-field-input-wrap')
|
||||
.merge(wrap);
|
||||
|
||||
if (nominatim && entity) {
|
||||
var center = entity.extent(context.graph()).center();
|
||||
if (nominatim && _entity) {
|
||||
var center = _entity.extent(context.graph()).center();
|
||||
nominatim.countryCode(center, initCallback);
|
||||
}
|
||||
}
|
||||
@@ -243,15 +243,15 @@ export function uiFieldAddress(field, context) {
|
||||
}
|
||||
|
||||
|
||||
address.entity = function(_) {
|
||||
if (!arguments.length) return entity;
|
||||
entity = _;
|
||||
address.entity = function(val) {
|
||||
if (!arguments.length) return _entity;
|
||||
_entity = val;
|
||||
return address;
|
||||
};
|
||||
|
||||
|
||||
address.tags = function(tags) {
|
||||
if (isInitialized) {
|
||||
if (_isInitialized) {
|
||||
updateTags(tags);
|
||||
} else {
|
||||
dispatch.on('init', function () {
|
||||
|
||||
@@ -92,12 +92,12 @@ export function uiFieldCheck(field, context) {
|
||||
checkImpliedYes();
|
||||
selection.classed('checkselect', 'true');
|
||||
|
||||
label = selection.selectAll('.preset-input-wrap')
|
||||
label = selection.selectAll('.form-field-input-wrap')
|
||||
.data([0]);
|
||||
|
||||
var enter = label.enter()
|
||||
.append('label')
|
||||
.attr('class', 'preset-input-wrap');
|
||||
.attr('class', 'form-field-input-wrap');
|
||||
|
||||
enter
|
||||
.append('input')
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import _keys from 'lodash-es/keys';
|
||||
|
||||
import { dispatch as d3_dispatch } from 'd3-dispatch';
|
||||
import { select as d3_select } from 'd3-selection';
|
||||
import { d3combobox as d3_combobox } from '../../lib/d3.combobox.js';
|
||||
@@ -12,8 +10,8 @@ import {
|
||||
|
||||
|
||||
export function uiFieldCycleway(field, context) {
|
||||
var dispatch = d3_dispatch('change'),
|
||||
items = d3_select(null);
|
||||
var dispatch = d3_dispatch('change');
|
||||
var items = d3_select(null);
|
||||
|
||||
|
||||
function cycleway(selection) {
|
||||
@@ -23,12 +21,12 @@ export function uiFieldCycleway(field, context) {
|
||||
}
|
||||
|
||||
|
||||
var wrap = selection.selectAll('.preset-input-wrap')
|
||||
var wrap = selection.selectAll('.form-field-input-wrap')
|
||||
.data([0]);
|
||||
|
||||
wrap = wrap.enter()
|
||||
.append('div')
|
||||
.attr('class', 'preset-input-wrap')
|
||||
.attr('class', 'form-field-input-wrap')
|
||||
.merge(wrap);
|
||||
|
||||
|
||||
@@ -77,9 +75,9 @@ export function uiFieldCycleway(field, context) {
|
||||
|
||||
|
||||
function change() {
|
||||
var left = utilGetSetValue(d3_select('.preset-input-cyclewayleft')),
|
||||
right = utilGetSetValue(d3_select('.preset-input-cyclewayright')),
|
||||
tag = {};
|
||||
var left = utilGetSetValue(d3_select('.preset-input-cyclewayleft'));
|
||||
var right = utilGetSetValue(d3_select('.preset-input-cyclewayright'));
|
||||
var tag = {};
|
||||
|
||||
if (left === 'none' || left === '') { left = undefined; }
|
||||
if (right === 'none' || right === '') { right = undefined; }
|
||||
@@ -106,7 +104,7 @@ export function uiFieldCycleway(field, context) {
|
||||
|
||||
|
||||
cycleway.options = function() {
|
||||
return _keys(field.strings.options).map(function(option) {
|
||||
return Object.keys(field.strings.options).map(function(option) {
|
||||
return {
|
||||
title: field.t('options.' + option + '.description'),
|
||||
value: option
|
||||
|
||||
@@ -6,26 +6,25 @@ import { utilGetDimensions } from '../../util/dimensions';
|
||||
|
||||
|
||||
export function uiFieldLanes(field, context) {
|
||||
var dispatch = d3_dispatch('change'),
|
||||
LANE_WIDTH = 40,
|
||||
LANE_HEIGHT = 200,
|
||||
wayID,
|
||||
lanesData;
|
||||
var dispatch = d3_dispatch('change');
|
||||
var LANE_WIDTH = 40;
|
||||
var LANE_HEIGHT = 200;
|
||||
var _entityID;
|
||||
|
||||
function lanes(selection) {
|
||||
lanesData = context.entity(wayID).lanes();
|
||||
var lanesData = context.entity(_entityID).lanes();
|
||||
|
||||
if (!d3_select('.inspector-wrap.inspector-hidden').empty() || !selection.node().parentNode) {
|
||||
selection.call(lanes.off);
|
||||
return;
|
||||
}
|
||||
|
||||
var wrap = selection.selectAll('.preset-input-wrap')
|
||||
var wrap = selection.selectAll('.form-field-input-wrap')
|
||||
.data([0]);
|
||||
|
||||
wrap = wrap.enter()
|
||||
.append('div')
|
||||
.attr('class', 'preset-input-wrap')
|
||||
.attr('class', 'form-field-input-wrap')
|
||||
.merge(wrap);
|
||||
|
||||
var surface = wrap.selectAll('.surface')
|
||||
@@ -123,9 +122,9 @@ export function uiFieldLanes(field, context) {
|
||||
}
|
||||
|
||||
|
||||
lanes.entity = function(_) {
|
||||
if (!wayID || wayID !== _.id) {
|
||||
wayID = _.id;
|
||||
lanes.entity = function(val) {
|
||||
if (!_entityID || _entityID !== val.id) {
|
||||
_entityID = val.id;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -14,15 +14,15 @@ import {
|
||||
|
||||
|
||||
export function uiFieldMaxspeed(field, context) {
|
||||
var dispatch = d3_dispatch('change'),
|
||||
entity,
|
||||
isImperial,
|
||||
unitInput = d3_select(null),
|
||||
input = d3_select(null),
|
||||
combobox;
|
||||
var dispatch = d3_dispatch('change');
|
||||
var _entity;
|
||||
var isImperial;
|
||||
var unitInput = d3_select(null);
|
||||
var input = d3_select(null);
|
||||
var combobox;
|
||||
|
||||
var metricValues = [20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],
|
||||
imperialValues = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80];
|
||||
var metricValues = [20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120];
|
||||
var imperialValues = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80];
|
||||
|
||||
|
||||
function maxspeed(selection) {
|
||||
@@ -50,11 +50,11 @@ export function uiFieldMaxspeed(field, context) {
|
||||
.on('blur', change);
|
||||
|
||||
var loc;
|
||||
if (entity.type === 'node') {
|
||||
loc = entity.loc;
|
||||
if (_entity.type === 'node') {
|
||||
loc = _entity.loc;
|
||||
}
|
||||
else {
|
||||
var childNodes = context.graph().childNodes(context.entity(entity.id));
|
||||
var childNodes = context.graph().childNodes(context.entity(_entity.id));
|
||||
loc = childNodes[~~(childNodes.length/2)].loc;
|
||||
}
|
||||
|
||||
@@ -103,8 +103,8 @@ export function uiFieldMaxspeed(field, context) {
|
||||
|
||||
|
||||
function change() {
|
||||
var tag = {},
|
||||
value = utilGetSetValue(input);
|
||||
var tag = {};
|
||||
var value = utilGetSetValue(input);
|
||||
|
||||
if (!value) {
|
||||
tag[field.key] = undefined;
|
||||
@@ -138,8 +138,8 @@ export function uiFieldMaxspeed(field, context) {
|
||||
};
|
||||
|
||||
|
||||
maxspeed.entity = function(_) {
|
||||
entity = _;
|
||||
maxspeed.entity = function(val) {
|
||||
_entity = val;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -14,16 +14,16 @@ export { uiFieldRadio as uiFieldStructureRadio };
|
||||
|
||||
|
||||
export function uiFieldRadio(field, context) {
|
||||
var dispatch = d3_dispatch('change'),
|
||||
placeholder = d3_select(null),
|
||||
wrap = d3_select(null),
|
||||
labels = d3_select(null),
|
||||
radios = d3_select(null),
|
||||
radioData = _clone(field.options || field.keys),
|
||||
typeField,
|
||||
layerField,
|
||||
oldType = {},
|
||||
entity;
|
||||
var dispatch = d3_dispatch('change');
|
||||
var placeholder = d3_select(null);
|
||||
var wrap = d3_select(null);
|
||||
var labels = d3_select(null);
|
||||
var radios = d3_select(null);
|
||||
var radioData = _clone(field.options || field.keys);
|
||||
var typeField;
|
||||
var layerField;
|
||||
var _oldType = {};
|
||||
var _entity;
|
||||
|
||||
|
||||
function selectedKey() {
|
||||
@@ -35,12 +35,12 @@ export function uiFieldRadio(field, context) {
|
||||
function radio(selection) {
|
||||
selection.classed('preset-radio', true);
|
||||
|
||||
wrap = selection.selectAll('.preset-input-wrap')
|
||||
wrap = selection.selectAll('.form-field-input-wrap')
|
||||
.data([0]);
|
||||
|
||||
var enter = wrap.enter()
|
||||
.append('div')
|
||||
.attr('class', 'preset-input-wrap toggle-list');
|
||||
.attr('class', 'form-field-input-wrap toggle-list');
|
||||
|
||||
enter
|
||||
.append('span')
|
||||
@@ -79,10 +79,10 @@ export function uiFieldRadio(field, context) {
|
||||
|
||||
|
||||
function structureExtras(selection, tags) {
|
||||
var selected = selectedKey(),
|
||||
type = context.presets().field(selected),
|
||||
layer = context.presets().field('layer'),
|
||||
showLayer = (selected === 'bridge' || selected === 'tunnel');
|
||||
var selected = selectedKey();
|
||||
var type = context.presets().field(selected);
|
||||
var layer = context.presets().field('layer');
|
||||
var showLayer = (selected === 'bridge' || selected === 'tunnel');
|
||||
|
||||
|
||||
var extrasWrap = selection.selectAll('.structure-extras-wrap')
|
||||
@@ -107,7 +107,7 @@ export function uiFieldRadio(field, context) {
|
||||
// Type
|
||||
if (type) {
|
||||
if (!typeField || typeField.id !== selected) {
|
||||
typeField = uiField(context, type, entity, { wrap: false })
|
||||
typeField = uiField(context, type, _entity, { wrap: false })
|
||||
.on('change', changeType);
|
||||
}
|
||||
typeField.tags(tags);
|
||||
@@ -150,7 +150,7 @@ export function uiFieldRadio(field, context) {
|
||||
// Layer
|
||||
if (layer && showLayer) {
|
||||
if (!layerField) {
|
||||
layerField = uiField(context, layer, entity, { wrap: false })
|
||||
layerField = uiField(context, layer, _entity, { wrap: false })
|
||||
.on('change', changeLayer);
|
||||
}
|
||||
layerField.tags(tags);
|
||||
@@ -199,7 +199,7 @@ export function uiFieldRadio(field, context) {
|
||||
|
||||
var val = t[key];
|
||||
if (val !== 'no') {
|
||||
oldType[key] = val;
|
||||
_oldType[key] = val;
|
||||
}
|
||||
|
||||
if (field.type === 'structureRadio') {
|
||||
@@ -233,8 +233,8 @@ export function uiFieldRadio(field, context) {
|
||||
|
||||
|
||||
function changeRadio() {
|
||||
var t = {},
|
||||
activeKey;
|
||||
var t = {};
|
||||
var activeKey;
|
||||
|
||||
if (field.key) {
|
||||
t[field.key] = undefined;
|
||||
@@ -247,7 +247,7 @@ export function uiFieldRadio(field, context) {
|
||||
if (field.key) {
|
||||
if (active) t[field.key] = d;
|
||||
} else {
|
||||
var val = oldType[activeKey] || 'yes';
|
||||
var val = _oldType[activeKey] || 'yes';
|
||||
t[d] = active ? val : undefined;
|
||||
}
|
||||
});
|
||||
@@ -284,14 +284,14 @@ export function uiFieldRadio(field, context) {
|
||||
placeholder.text(t('inspector.none'));
|
||||
} else {
|
||||
placeholder.text(selection.attr('value'));
|
||||
oldType[selection.datum()] = tags[selection.datum()];
|
||||
_oldType[selection.datum()] = tags[selection.datum()];
|
||||
}
|
||||
|
||||
if (field.type === 'structureRadio') {
|
||||
// For waterways without a tunnel tag, set 'culvert' as
|
||||
// the oldType to default to if the user picks 'tunnel'
|
||||
if (!!tags.waterway && !oldType.tunnel) {
|
||||
oldType.tunnel = 'culvert';
|
||||
// the _oldType to default to if the user picks 'tunnel'
|
||||
if (!!tags.waterway && !_oldType.tunnel) {
|
||||
_oldType.tunnel = 'culvert';
|
||||
}
|
||||
|
||||
wrap.call(structureExtras, tags);
|
||||
@@ -304,10 +304,10 @@ export function uiFieldRadio(field, context) {
|
||||
};
|
||||
|
||||
|
||||
radio.entity = function(_) {
|
||||
if (!arguments.length) return entity;
|
||||
entity = _;
|
||||
oldType = {};
|
||||
radio.entity = function(val) {
|
||||
if (!arguments.length) return _entity;
|
||||
_entity = val;
|
||||
_oldType = {};
|
||||
return radio;
|
||||
};
|
||||
|
||||
|
||||
@@ -102,12 +102,12 @@ export function uiFieldRestrictions(field, context) {
|
||||
}
|
||||
|
||||
|
||||
var wrap = selection.selectAll('.preset-input-wrap')
|
||||
var wrap = selection.selectAll('.form-field-input-wrap')
|
||||
.data([0]);
|
||||
|
||||
wrap = wrap.enter()
|
||||
.append('div')
|
||||
.attr('class', 'preset-input-wrap')
|
||||
.attr('class', 'form-field-input-wrap')
|
||||
.merge(wrap);
|
||||
|
||||
var container = wrap.selectAll('.restriction-container')
|
||||
|
||||
@@ -24,14 +24,14 @@ import {
|
||||
|
||||
|
||||
export function uiFieldWikipedia(field, context) {
|
||||
var dispatch = d3_dispatch('change'),
|
||||
wikipedia = services.wikipedia,
|
||||
wikidata = services.wikidata,
|
||||
link = d3_select(null),
|
||||
lang = d3_select(null),
|
||||
title = d3_select(null),
|
||||
wikiURL = '',
|
||||
entity;
|
||||
var dispatch = d3_dispatch('change');
|
||||
var wikipedia = services.wikipedia;
|
||||
var wikidata = services.wikidata;
|
||||
var link = d3_select(null);
|
||||
var lang = d3_select(null);
|
||||
var title = d3_select(null);
|
||||
var _wikiURL = '';
|
||||
var _entity;
|
||||
|
||||
|
||||
function wiki(selection) {
|
||||
@@ -53,7 +53,7 @@ export function uiFieldWikipedia(field, context) {
|
||||
.container(context.container())
|
||||
.fetcher(function(value, cb) {
|
||||
if (!value) {
|
||||
value = context.entity(entity.id).tags.name || '';
|
||||
value = context.entity(_entity.id).tags.name || '';
|
||||
}
|
||||
|
||||
var searchfn = value.length > 7 ? wikipedia.search : wikipedia.suggestions;
|
||||
@@ -114,7 +114,7 @@ export function uiFieldWikipedia(field, context) {
|
||||
link
|
||||
.on('click', function() {
|
||||
d3_event.preventDefault();
|
||||
if (wikiURL) window.open(wikiURL, '_blank');
|
||||
if (_wikiURL) window.open(_wikiURL, '_blank');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -144,10 +144,10 @@ export function uiFieldWikipedia(field, context) {
|
||||
|
||||
|
||||
function change(skipWikidata) {
|
||||
var value = utilGetSetValue(title),
|
||||
m = value.match(/https?:\/\/([-a-z]+)\.wikipedia\.org\/(?:wiki|\1-[-a-z]+)\/([^#]+)(?:#(.+))?/),
|
||||
l = m && _find(dataWikipedia, function(d) { return m[1] === d[2]; }),
|
||||
syncTags = {};
|
||||
var value = utilGetSetValue(title);
|
||||
var m = value.match(/https?:\/\/([-a-z]+)\.wikipedia\.org\/(?:wiki|\1-[-a-z]+)\/([^#]+)(?:#(.+))?/);
|
||||
var l = m && _find(dataWikipedia, function(d) { return m[1] === d[2]; });
|
||||
var syncTags = {};
|
||||
|
||||
if (l) {
|
||||
// Normalize title http://www.mediawiki.org/wiki/API:Query#Title_normalization
|
||||
@@ -180,8 +180,8 @@ export function uiFieldWikipedia(field, context) {
|
||||
if (skipWikidata || !value || !language()[2]) return;
|
||||
|
||||
// attempt asynchronous update of wikidata tag..
|
||||
var initGraph = context.graph(),
|
||||
initEntityId = entity.id;
|
||||
var initGraph = context.graph();
|
||||
var initEntityID = _entity.id;
|
||||
|
||||
wikidata.itemsByTitle(language()[2], value, function(title, data) {
|
||||
// If graph has changed, we can't apply this update.
|
||||
@@ -191,13 +191,13 @@ export function uiFieldWikipedia(field, context) {
|
||||
|
||||
var qids = Object.keys(data);
|
||||
var value = qids && _find(qids, function(id) { return id.match(/^Q\d+$/); });
|
||||
var currTags = _clone(context.entity(initEntityId).tags);
|
||||
var currTags = _clone(context.entity(initEntityID).tags);
|
||||
|
||||
currTags.wikidata = value;
|
||||
|
||||
// Coalesce the update of wikidata tag into the previous tag change
|
||||
context.overwrite(
|
||||
actionChangeTags(initEntityId, currTags),
|
||||
actionChangeTags(initEntityID, currTags),
|
||||
context.history().undoAnnotation()
|
||||
);
|
||||
|
||||
@@ -208,10 +208,10 @@ export function uiFieldWikipedia(field, context) {
|
||||
|
||||
|
||||
wiki.tags = function(tags) {
|
||||
var value = tags[field.key] || '',
|
||||
m = value.match(/([^:]+):([^#]+)(?:#(.+))?/),
|
||||
l = m && _find(dataWikipedia, function(d) { return m[1] === d[2]; }),
|
||||
anchor = m && m[3];
|
||||
var value = tags[field.key] || '';
|
||||
var m = value.match(/([^:]+):([^#]+)(?:#(.+))?/);
|
||||
var l = m && _find(dataWikipedia, function(d) { return m[1] === d[2]; });
|
||||
var anchor = m && m[3];
|
||||
|
||||
// value in correct format
|
||||
if (l) {
|
||||
@@ -225,7 +225,7 @@ export function uiFieldWikipedia(field, context) {
|
||||
anchor = anchor.replace(/ /g, '_');
|
||||
}
|
||||
}
|
||||
wikiURL = 'https://' + m[1] + '.wikipedia.org/wiki/' +
|
||||
_wikiURL = 'https://' + m[1] + '.wikipedia.org/wiki/' +
|
||||
m[2].replace(/ /g, '_') + (anchor ? ('#' + anchor) : '');
|
||||
|
||||
// unrecognized value format
|
||||
@@ -233,17 +233,17 @@ export function uiFieldWikipedia(field, context) {
|
||||
utilGetSetValue(title, value);
|
||||
if (value && value !== '') {
|
||||
utilGetSetValue(lang, '');
|
||||
wikiURL = 'https://en.wikipedia.org/wiki/Special:Search?search=' + value;
|
||||
_wikiURL = 'https://en.wikipedia.org/wiki/Special:Search?search=' + value;
|
||||
} else {
|
||||
wikiURL = '';
|
||||
_wikiURL = '';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
wiki.entity = function(_) {
|
||||
if (!arguments.length) return entity;
|
||||
entity = _;
|
||||
wiki.entity = function(val) {
|
||||
if (!arguments.length) return _entity;
|
||||
_entity = val;
|
||||
return wiki;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user