mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-31 04:09:33 +02:00
feat(fields/combo): add navigate button to web links in "chip" fields (#9974)
The common use case is for the `sources` key, often you have multiple URLs separated with semicolon. This allow to navigate to URL and check them more easily instead of doing manual work to select the URL copy and paste. Created with the help of Martin Raifer at the sotmeu2023!
This commit is contained in:
@@ -677,7 +677,12 @@ export function uiFieldCombo(field, context) {
|
||||
.attr('class', 'chip');
|
||||
|
||||
enter.append('span');
|
||||
enter.append('a');
|
||||
const field_buttons = enter
|
||||
.append('div')
|
||||
.attr('class', 'field_buttons');
|
||||
field_buttons
|
||||
.append('a')
|
||||
.attr('class', 'remove');
|
||||
|
||||
chips = chips.merge(enter)
|
||||
.order()
|
||||
@@ -714,17 +719,35 @@ export function uiFieldCombo(field, context) {
|
||||
registerDragAndDrop(chips);
|
||||
}
|
||||
|
||||
chips.select('span').each(function(d) {
|
||||
chips.each(function(d) {
|
||||
const selection = d3_select(this);
|
||||
if (d.display) {
|
||||
selection.text('');
|
||||
d.display(selection);
|
||||
} else {
|
||||
selection.text(d.value);
|
||||
const text_span = selection.select('span');
|
||||
const field_buttons = selection.select('.field_buttons');
|
||||
const clean_value = d.value.trim();
|
||||
text_span.text('');
|
||||
if (clean_value.startsWith('https://')) {
|
||||
// create a button to open the link in a new tab
|
||||
text_span.text(clean_value);
|
||||
field_buttons.select('button').remove();
|
||||
field_buttons.append('button')
|
||||
.call(svgIcon('#iD-icon-out-link'))
|
||||
.attr('class', 'form-field-button foreign-id-permalink')
|
||||
.attr('title', () => t('icons.visit_website'))
|
||||
.attr('aria-label', () => t('icons.visit_website'))
|
||||
.on('click', function(d3_event) {
|
||||
d3_event.preventDefault();
|
||||
window.open(clean_value, '_blank');
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (d.display) {
|
||||
d.display(text_span);
|
||||
return;
|
||||
}
|
||||
text_span.text(d.value);
|
||||
});
|
||||
|
||||
chips.select('a')
|
||||
chips.select('a.remove')
|
||||
.attr('href', '#')
|
||||
.on('click', removeMultikey)
|
||||
.attr('class', 'remove')
|
||||
|
||||
Reference in New Issue
Block a user