diff --git a/js/id/taginfo.js b/js/id/taginfo.js
index b06f1e8d5..b8c77d168 100644
--- a/js/id/taginfo.js
+++ b/js/id/taginfo.js
@@ -2,23 +2,29 @@ iD.taginfo = function() {
var taginfo = {},
endpoint = 'http://taginfo.openstreetmap.org/api/2/';
- taginfo.values = function(key, callback) {
- d3.json(endpoint + 'db/keys/values?' +
- iD.util.qsString({
- key: key,
+ taginfo.keys = function(parameters, callback) {
+ d3.json(endpoint + 'db/keys?' +
+ iD.util.qsString(_.extend({
rp: 20,
sortname: 'count_all',
sortorder: 'desc',
page: 1
- }), callback);
+ }, parameters)), callback);
};
- taginfo.docs = function(keyvalue, callback) {
+ taginfo.values = function(parameters, callback) {
+ d3.json(endpoint + 'db/keys/values?' +
+ iD.util.qsString(_.extend({
+ rp: 20,
+ sortname: 'count_all',
+ sortorder: 'desc',
+ page: 1
+ }, parameters)), callback);
+ };
+
+ taginfo.docs = function(parameters, callback) {
d3.json(endpoint + 'wiki/tags?' +
- iD.util.qsString({
- key: keyvalue.key,
- value: keyvalue.value
- }), callback);
+ iD.util.qsString(parameters), callback);
};
taginfo.endpoint = function(_) {
diff --git a/js/id/ui/inspector.js b/js/id/ui/inspector.js
index e44c00fa2..f9d133f6d 100644
--- a/js/id/ui/inspector.js
+++ b/js/id/ui/inspector.js
@@ -52,12 +52,26 @@ iD.Inspector = function() {
}
}
- function bindTypeahead(d, i) {
- var selection = d3.select(this);
- selection.call(d3.typeahead()
- .data(function(selection, callback) {
- taginfo.values(selection.datum().key, function(err, data) {
- callback(data.data);
+ function bindTypeahead() {
+ var row = d3.select(this),
+ key = row.selectAll('.key'),
+ value = row.selectAll('.value');
+
+ key.call(d3.typeahead()
+ .data(function(_, callback) {
+ taginfo.keys({query: key.property('value')}, function(err, data) {
+ callback(data.data.map(function (d) {
+ return {value: d.key};
+ }));
+ });
+ }));
+
+ value.call(d3.typeahead()
+ .data(function(_, callback) {
+ taginfo.values({key: key.property('value'), query: value.property('value')}, function(err, data) {
+ callback(data.data.map(function (d) {
+ return {value: d.value, title: d.description};
+ }));
});
}));
}
@@ -84,8 +98,9 @@ iD.Inspector = function() {
.property('type', 'text')
.attr('class', 'value')
.property('value', function(d) { return d.value; })
- .on('keydown.push-more', pushMore)
- .each(bindTypeahead);
+ .on('keydown.push-more', pushMore);
+
+ inputs.each(bindTypeahead);
var removeBtn = row.append('button')
.attr('tabindex', -1)
diff --git a/js/lib/d3.typeahead.js b/js/lib/d3.typeahead.js
index ea949abad..a93da8877 100644
--- a/js/lib/d3.typeahead.js
+++ b/js/lib/d3.typeahead.js
@@ -1,8 +1,9 @@
d3.typeahead = function() {
- var data, hidden;
+ var data;
var typeahead = function(selection) {
- var container;
+ var container, hidden, idx = 0;
+
function setup() {
var rect = selection.node().getBoundingClientRect();
container = d3.select(document.body)
@@ -29,40 +30,35 @@ d3.typeahead = function() {
.on('focus.typeahead', setup)
.on('blur.typeahead', hide);
- var idx = 0;
function update() {
if (hidden) setup();
+
if (d3.event.keyCode === 40) idx++;
if (d3.event.keyCode === 38) idx--;
if (d3.event.keyCode === 13) {
selection.property('value', container.select('a.selected').datum().value);
hide();
}
+
container
.selectAll('a')
.classed('selected', function(d, i) { return i == idx; });
- // if (d3.event.keyCode === 13) // return
+
data(selection, function(data) {
- var val = selection.property('value'),
- matches = data.filter(function(d) {
- return d.value.toLowerCase().indexOf(val) === 0;
- }).map(function(d) {
- return { value: d.value, description: d.description };
- });
container.style('display', function() {
- return matches.length ? 'block' : 'none';
+ return data.length ? 'block' : 'none';
});
+
var options = container
.selectAll('a')
- .data(matches, function(d) { return d.value; });
+ .data(data, function(d) { return d.value; });
options.enter()
.append('a')
.text(function(d) { return d.value; })
- .attr('title', function(d) { return d.description; })
- .on('click', function(d) {
- selection.property('value', d.value);
- });
+ .attr('title', function(d) { return d.title; })
+ .on('click', function(d) { selection.property('value', d.value); });
+
options.exit().remove();
});
}
diff --git a/test/index.html b/test/index.html
index c1e6716a1..3d0a995c3 100644
--- a/test/index.html
+++ b/test/index.html
@@ -131,6 +131,7 @@
+
+