refactor further modules to not rely on html injection

This commit is contained in:
Martin Raifer
2022-06-24 19:31:41 +02:00
parent 209cc23d92
commit 7d546a8f60
6 changed files with 15 additions and 8 deletions
+3 -1
View File
@@ -376,7 +376,7 @@ export function coreLocalizer() {
// Adds localized text wrapped as an HTML span element with locale info to the DOM
localizer.t.append = function(stringId, replacements, locale) {
return function(selection) {
const ret = function(selection) {
const info = localizer.tInfo(stringId, replacements, locale);
return selection.append('span')
.attr('class', 'localized-text')
@@ -385,6 +385,8 @@ export function coreLocalizer() {
+ info.text
+ (replacements &&replacements.suffix || ''));
};
ret.stringId = stringId;
return ret;
};
localizer.languageName = (code, options) => {
+3 -1
View File
@@ -250,7 +250,9 @@ export function rendererTileLayer(context) {
if (result && result.vintage && result.vintage.range) {
span.text(result.vintage.range);
} else {
span.html(t.html('info_panels.background.vintage') + ': ' + t.html('info_panels.background.unknown'));
span.call(t.append('info_panels.background.vintage'));
span.append('span').text(': ');
span.call(t.append('info_panels.background.unknown'));
}
});
});
+1 -1
View File
@@ -34,7 +34,7 @@ export function uiCommitWarnings(context) {
containerEnter
.append('h3')
.html(severity === 'warning' ? t.html('commit.warnings') : t.html('commit.errors'));
.call(severity === 'warning' ? t.append('commit.warnings') : t.append('commit.errors'));
containerEnter
.append('ul')
+2 -1
View File
@@ -65,7 +65,8 @@ export function uiEntityEditor(context) {
.merge(headerEnter);
header.selectAll('h2')
.html(_entityIDs.length === 1 ? t.html('inspector.edit') : t.html('inspector.edit_features'));
.text('')
.call(_entityIDs.length === 1 ? t.append('inspector.edit') : t.append('inspector.edit_features'));
header.selectAll('.preset-reset')
.on('click', function() {
+2 -1
View File
@@ -399,10 +399,11 @@ export function uiPresetList(context) {
].filter(Boolean);
label.selectAll('.namepart')
.data(nameparts)
.data(nameparts, d => d.stringId)
.enter()
.append('div')
.attr('class', 'namepart')
.text('')
.each(function(d) { d(d3_select(this)); });
wrap.call(item.reference.button);
+4 -3
View File
@@ -96,11 +96,11 @@ export function uiSectionFeatureType(context) {
var names = _presets.length === 1 ? [
_presets[0].nameLabel(),
_presets[0].subtitleLabel()
].filter(Boolean) : [t('inspector.multiple_types')];
].filter(Boolean) : [ t.append('inspector.multiple_types') ];
var label = selection.select('.label-inner');
var nameparts = label.selectAll('.namepart')
.data(names, function(d) { return d; });
.data(names, d => d.stringId);
nameparts.exit()
.remove();
@@ -109,7 +109,8 @@ export function uiSectionFeatureType(context) {
.enter()
.append('div')
.attr('class', 'namepart')
.each(function(d) { return d(d3_select(this)); });
.text('')
.each(function(d) { d(d3_select(this)); });
}
section.entityIDs = function(val) {