From dab742a5010d18a11a1ebebc8d5ead921ce78636 Mon Sep 17 00:00:00 2001 From: Sajjad Anwar Date: Fri, 24 Oct 2014 15:35:59 -0400 Subject: [PATCH] Make taginfo configurable and default to disabling taginfo related features --- dist/index.html | 3 ++- index.html | 1 + js/id/id.js | 8 ++++++++ js/id/ui/entity_editor.js | 2 +- js/id/ui/preset.js | 2 +- js/id/ui/preset/combo.js | 6 +++--- js/id/ui/preset_list.js | 2 +- js/id/ui/raw_tag_editor.js | 11 ++++++----- js/id/ui/tag_reference.js | 9 +++++---- 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/dist/index.html b/dist/index.html index 16fafe5d8..572d4a761 100644 --- a/dist/index.html +++ b/dist/index.html @@ -66,7 +66,8 @@ } else { var id = iD() .presets(iD.data.presets) - .imagery(iD.data.imagery); + .imagery(iD.data.imagery) + .taginfo(iD.taginfo()); d3.select('#id-container') .call(id.ui()); diff --git a/index.html b/index.html index ded7dcabf..cdff162bf 100644 --- a/index.html +++ b/index.html @@ -232,6 +232,7 @@ id = iD() .presets(iD.data.presets) .imagery(iD.data.imagery) + .taginfo(iD.taginfo()) .assetPath('dist/'); d3.select('#id-container') diff --git a/js/id/id.js b/js/id/id.js index 3d1a05788..96d9c347d 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -243,6 +243,14 @@ window.iD = function () { return context; }; + /* Taginfo */ + var taginfo; + context.taginfo = function(_) { + if (!arguments.length) return taginfo; + taginfo = _; + return context; + }; + var embed = false; context.embed = function(_) { if (!arguments.length) return embed; diff --git a/js/id/ui/entity_editor.js b/js/id/ui/entity_editor.js index bc20bfb52..206e868da 100644 --- a/js/id/ui/entity_editor.js +++ b/js/id/ui/entity_editor.js @@ -172,7 +172,7 @@ iD.ui.EntityEditor = function(context) { if (!arguments.length) return preset; if (_ !== preset) { preset = _; - reference = iD.ui.TagReference(preset.reference(context.geometry(id))) + reference = iD.ui.TagReference(preset.reference(context.geometry(id)), context) .showing(false); } return entityEditor; diff --git a/js/id/ui/preset.js b/js/id/ui/preset.js index cb8964a7a..2d7e62718 100644 --- a/js/id/ui/preset.js +++ b/js/id/ui/preset.js @@ -138,7 +138,7 @@ iD.ui.preset = function(context) { return field.present(); }) .each(function(field) { - var reference = iD.ui.TagReference(field.reference || {key: field.key}); + var reference = iD.ui.TagReference(field.reference || {key: field.key}, context); if (state === 'hover') { reference.showing(false); diff --git a/js/id/ui/preset/combo.js b/js/id/ui/preset/combo.js index dc1b93d88..e6c6e17b0 100644 --- a/js/id/ui/preset/combo.js +++ b/js/id/ui/preset/combo.js @@ -1,5 +1,5 @@ iD.ui.preset.combo = -iD.ui.preset.typeCombo = function(field) { +iD.ui.preset.typeCombo = function(field, context) { var event = d3.dispatch('change'), optstrings = field.strings && field.strings.options, optarray = field.options, @@ -34,8 +34,8 @@ iD.ui.preset.typeCombo = function(field) { strings[k] = k.replace(/_+/g, ' '); }); stringsLoaded(); - } else { - iD.taginfo().values({key: field.key}, function(err, data) { + } else if (context.taginfo()) { + context.taginfo().values({key: field.key}, function(err, data) { if (!err) { _.each(_.pluck(data, 'value'), function(k) { strings[k] = k.replace(/_+/g, ' '); diff --git a/js/id/ui/preset_list.js b/js/id/ui/preset_list.js index 31b35a56a..4ae2952da 100644 --- a/js/id/ui/preset_list.js +++ b/js/id/ui/preset_list.js @@ -213,7 +213,7 @@ iD.ui.PresetList = function(context) { }; item.preset = preset; - item.reference = iD.ui.TagReference(preset.reference(context.geometry(id))); + item.reference = iD.ui.TagReference(preset.reference(context.geometry(id)), context); return item; } diff --git a/js/id/ui/raw_tag_editor.js b/js/id/ui/raw_tag_editor.js index f9c9de251..8bacb7b89 100644 --- a/js/id/ui/raw_tag_editor.js +++ b/js/id/ui/raw_tag_editor.js @@ -1,6 +1,5 @@ iD.ui.RawTagEditor = function(context) { var event = d3.dispatch('change'), - taginfo = iD.taginfo(), showBlank = false, state, preset, @@ -77,14 +76,16 @@ iD.ui.RawTagEditor = function(context) { .append('span') .attr('class', 'icon delete'); - $enter.each(bindTypeahead); + if (context.taginfo()) { + $enter.each(bindTypeahead); + } // Update $items.order(); $items.each(function(tag) { - var reference = iD.ui.TagReference({key: tag.key}); + var reference = iD.ui.TagReference({key: tag.key}, context); if (state === 'hover') { reference.showing(false); @@ -139,7 +140,7 @@ iD.ui.RawTagEditor = function(context) { key.call(d3.combobox() .fetcher(function(value, callback) { - taginfo.keys({ + context.taginfo().keys({ debounce: true, geometry: context.geometry(id), query: value @@ -150,7 +151,7 @@ iD.ui.RawTagEditor = function(context) { value.call(d3.combobox() .fetcher(function(value, callback) { - taginfo.values({ + context.taginfo().values({ debounce: true, key: key.value(), geometry: context.geometry(id), diff --git a/js/id/ui/tag_reference.js b/js/id/ui/tag_reference.js index 8bda8f287..aaaec563d 100644 --- a/js/id/ui/tag_reference.js +++ b/js/id/ui/tag_reference.js @@ -1,6 +1,5 @@ -iD.ui.TagReference = function(tag) { +iD.ui.TagReference = function(tag, context) { var tagReference = {}, - taginfo = iD.taginfo(), button, body, loaded, @@ -34,7 +33,7 @@ iD.ui.TagReference = function(tag) { function load() { button.classed('tag-reference-loading', true); - taginfo.docs(tag, function(err, docs) { + context.taginfo().docs(tag, function(err, docs) { if (!err && docs) { docs = findLocal(docs); } @@ -117,7 +116,9 @@ iD.ui.TagReference = function(tag) { } else if (loaded) { show(); } else { - load(); + if (context.taginfo()) { + load(); + } } }); };