From ccb5b81645ff2feb3b32e6ea116dd7c67d28c107 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sat, 9 Feb 2013 15:35:25 -0800 Subject: [PATCH] Clean up geocoder Pass context directly; fix indentation; i18n. --- js/id/ui.js | 2 +- js/id/ui/geocoder.js | 45 +++++++++++++------------------------------- locale/en.js | 5 +++-- 3 files changed, 17 insertions(+), 35 deletions(-) diff --git a/js/id/ui.js b/js/id/ui.js index 81797b731..3b13c2847 100644 --- a/js/id/ui.js +++ b/js/id/ui.js @@ -128,7 +128,7 @@ iD.ui = function(context) { } container.append('div').attr('class', 'geocode-control map-control') - .call(iD.ui.geocoder().map(map).context(context)); + .call(iD.ui.geocoder(context)); container.append('div').attr('class', 'map-control layerswitcher-control') .call(iD.ui.layerswitcher(context)); diff --git a/js/id/ui/geocoder.js b/js/id/ui/geocoder.js index 7f1a6ca4c..04f68f1ba 100644 --- a/js/id/ui/geocoder.js +++ b/js/id/ui/geocoder.js @@ -1,7 +1,4 @@ -iD.ui.geocoder = function() { - - var map, context; - +iD.ui.geocoder = function(context) { function resultExtent(bounds) { return new iD.geo.Extent( [parseFloat(bounds[3]), parseFloat(bounds[0])], @@ -20,7 +17,7 @@ iD.ui.geocoder = function() { return iD.ui.flash(context.container()) .select('.content') .append('h3') - .text('No location found for "' + searchVal + '"'); + .text(t('geocoder.no_results', {name: searchVal})); } else if (resp.length > 1) { var spans = resultsList.selectAll('span') .data(resp, function (d) { return d.place_id; }); @@ -53,19 +50,11 @@ iD.ui.geocoder = function() { function applyBounds(extent) { hide(); + var map = context.map(); map.extent(extent); if (map.zoom() > 19) map.zoom(19); } - function clickoutside(selection) { - selection - .on('click.geocoder-inside', function() { - return d3.event.stopPropagation(); - }); - context.container().on('click.geocoder-outside', hide); - } - - function show() { setVisible(true); } function hide() { setVisible(false); } function toggle() { setVisible(gcForm.classed('hide')); } @@ -79,34 +68,26 @@ iD.ui.geocoder = function() { var button = selection.append('button') .attr('tabindex', -1) - .attr('title', t('geocoder.find_location')) + .attr('title', t('geocoder.title')) .html('') .on('click', toggle); var gcForm = selection.append('form'); - var inputNode = gcForm.attr('class','content fillD map-overlay hide') + var inputNode = gcForm.attr('class', 'content fillD map-overlay hide') .append('input') - .attr({ type: 'text', placeholder: t('geocoder.find_a_place') }) - .on('keydown', keydown); + .attr({ type: 'text', placeholder: t('geocoder.placeholder') }) + .on('keydown', keydown); var resultsList = selection.append('div') - .attr('class','content fillD map-overlay hide'); + .attr('class', 'content fillD map-overlay hide'); - selection.call(clickoutside); + selection.on('click.geocoder-inside', function() { + return d3.event.stopPropagation(); + }); + + context.container().on('click.geocoder-outside', hide); } - geocoder.map = function(_) { - if (!arguments.length) return map; - map = _; - return geocoder; - }; - - geocoder.context = function(_) { - if (!arguments.length) return context; - context = _; - return geocoder; - }; - return geocoder; }; diff --git a/locale/en.js b/locale/en.js index 6c4f8bc2b..1f354013b 100644 --- a/locale/en.js +++ b/locale/en.js @@ -169,8 +169,9 @@ locale.en = { edit_tags: "Edit tags", geocoder: { - "find_location": "Find A Location", - "find_a_place": "find a place" + title: "Find A Place", + placeholder: "find a place", + no_results: "Couldn't locate a place named '{name}'" }, description: "Description",