mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-30 19:59:35 +02:00
Reduce use of global selection (re: #7445)
This commit is contained in:
@@ -68,7 +68,7 @@ export function uiFieldCheck(field, context) {
|
||||
|
||||
|
||||
function reverserHidden() {
|
||||
if (!d3_select('div.inspector-hover').empty()) return true;
|
||||
if (!context.container().select('div.inspector-hover').empty()) return true;
|
||||
return !(_value === 'yes' || (_impliedYes && !_value));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { dispatch as d3_dispatch } from 'd3-dispatch';
|
||||
import { select as d3_select } from 'd3-selection';
|
||||
|
||||
import { utilRebind } from '../../util/rebind';
|
||||
import { utilGetDimensions } from '../../util/dimensions';
|
||||
@@ -14,7 +13,7 @@ export function uiFieldLanes(field, context) {
|
||||
function lanes(selection) {
|
||||
var lanesData = context.entity(_entityIDs[0]).lanes();
|
||||
|
||||
if (!d3_select('.inspector-wrap.inspector-hidden').empty() || !selection.node().parentNode) {
|
||||
if (!context.container().select('.inspector-wrap.inspector-hidden').empty() || !selection.node().parentNode) {
|
||||
selection.call(lanes.off);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ export function uiFieldRestrictions(field, context) {
|
||||
|
||||
// if form field is hidden or has detached from dom, clean up.
|
||||
if (!isOK ||
|
||||
!d3_select('.inspector-wrap.inspector-hidden').empty() ||
|
||||
!context.container().select('.inspector-wrap.inspector-hidden').empty() ||
|
||||
!selection.node().parentNode ||
|
||||
!selection.node().parentNode.parentNode) {
|
||||
selection.call(restrictions.off);
|
||||
@@ -209,7 +209,7 @@ export function uiFieldRestrictions(field, context) {
|
||||
// width: calc as sidebar - padding
|
||||
// height: hardcoded (from `80_app.css`)
|
||||
// var d = utilGetDimensions(selection);
|
||||
var sdims = utilGetDimensions(d3_select('.sidebar'));
|
||||
var sdims = utilGetDimensions(context.container().select('.sidebar'));
|
||||
var d = [ sdims[0] - 50, 370 ];
|
||||
var c = geoVecScale(d, 0.5);
|
||||
var z = 22;
|
||||
@@ -407,7 +407,7 @@ export function uiFieldRestrictions(field, context) {
|
||||
var xPos = -1;
|
||||
|
||||
if (minChange) {
|
||||
xPos = utilGetDimensions(d3_select('.sidebar'))[0];
|
||||
xPos = utilGetDimensions(context.container().select('.sidebar'))[0];
|
||||
}
|
||||
|
||||
if (!minChange || (minChange && Math.abs(xPos - _lastXPos) >= minChange)) {
|
||||
|
||||
@@ -23,7 +23,9 @@ import { t } from '../../util/locale';
|
||||
export function uiFieldWikidata(field, context) {
|
||||
var wikidata = services.wikidata;
|
||||
var dispatch = d3_dispatch('change');
|
||||
var searchInput = d3_select(null);
|
||||
|
||||
var _selection = d3_select(null);
|
||||
var _searchInput = d3_select(null);
|
||||
var _qid = null;
|
||||
var _wikidataEntity = null;
|
||||
var _wikiURL = '';
|
||||
@@ -40,6 +42,8 @@ export function uiFieldWikidata(field, context) {
|
||||
|
||||
function wiki(selection) {
|
||||
|
||||
_selection = selection;
|
||||
|
||||
var wrap = selection.selectAll('.form-field-input-wrap')
|
||||
.data([0]);
|
||||
|
||||
@@ -64,14 +68,14 @@ export function uiFieldWikidata(field, context) {
|
||||
.append('li')
|
||||
.attr('class', 'wikidata-search');
|
||||
|
||||
searchInput = searchRowEnter
|
||||
_searchInput = searchRowEnter
|
||||
.append('input')
|
||||
.attr('type', 'text')
|
||||
.attr('id', field.domId)
|
||||
.style('flex', '1')
|
||||
.call(utilNoAuto);
|
||||
|
||||
searchInput
|
||||
_searchInput
|
||||
.on('focus', function() {
|
||||
var node = d3_select(this).node();
|
||||
node.setSelectionRange(0, node.value.length);
|
||||
@@ -277,14 +281,14 @@ export function uiFieldWikidata(field, context) {
|
||||
label = _wikidataEntity.id.toString();
|
||||
}
|
||||
}
|
||||
utilGetSetValue(d3_select('li.wikidata-search input'), label);
|
||||
utilGetSetValue(_searchInput, label);
|
||||
}
|
||||
|
||||
|
||||
wiki.tags = function(tags) {
|
||||
|
||||
var isMixed = Array.isArray(tags[field.key]);
|
||||
d3_select('li.wikidata-search input')
|
||||
_searchInput
|
||||
.attr('title', isMixed ? tags[field.key].filter(Boolean).join('\n') : null)
|
||||
.attr('placeholder', isMixed ? t('inspector.multiple_values') : '')
|
||||
.classed('mixed', isMixed);
|
||||
@@ -309,17 +313,17 @@ export function uiFieldWikidata(field, context) {
|
||||
|
||||
var description = entityPropertyForDisplay(entity, 'descriptions');
|
||||
|
||||
d3_select('.form-field-wikidata button.wiki-link')
|
||||
_selection.select('button.wiki-link')
|
||||
.classed('disabled', false);
|
||||
|
||||
d3_select('.preset-wikidata-description')
|
||||
_selection.select('.preset-wikidata-description')
|
||||
.style('display', function(){
|
||||
return description.length > 0 ? 'flex' : 'none';
|
||||
})
|
||||
.select('input')
|
||||
.attr('value', description);
|
||||
|
||||
d3_select('.preset-wikidata-identifier')
|
||||
_selection.select('.preset-wikidata-identifier')
|
||||
.style('display', function(){
|
||||
return entity.id ? 'flex' : 'none';
|
||||
})
|
||||
@@ -333,12 +337,12 @@ export function uiFieldWikidata(field, context) {
|
||||
_wikidataEntity = null;
|
||||
setLabelForEntity();
|
||||
|
||||
d3_select('.preset-wikidata-description')
|
||||
_selection.select('.preset-wikidata-description')
|
||||
.style('display', 'none');
|
||||
d3_select('.preset-wikidata-identifier')
|
||||
_selection.select('.preset-wikidata-identifier')
|
||||
.style('display', 'none');
|
||||
|
||||
d3_select('.form-field-wikidata button.wiki-link')
|
||||
_selection.select('button.wiki-link')
|
||||
.classed('disabled', true);
|
||||
|
||||
if (_qid && _qid !== '') {
|
||||
@@ -374,7 +378,7 @@ export function uiFieldWikidata(field, context) {
|
||||
|
||||
|
||||
wiki.focus = function() {
|
||||
searchInput.node().focus();
|
||||
_searchInput.node().focus();
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user