From 053ba51e2769bc15937e71e9cda52a7f416b0027 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 28 May 2013 10:56:54 -0700 Subject: [PATCH 1/5] Clear sidebar when not hovering (fixes #1528) --- js/id/ui/inspector.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/js/id/ui/inspector.js b/js/id/ui/inspector.js index 5bf8a6b74..b66d90dde 100644 --- a/js/id/ui/inspector.js +++ b/js/id/ui/inspector.js @@ -6,8 +6,6 @@ iD.ui.Inspector = function(context) { newFeature = false; function inspector(selection) { - selection.style('display', 'block'); - var $wrap = selection.selectAll('.panewrap') .data([0]); From 39222caac9a8f1fa367838727cc0b286b351e53d Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 28 May 2013 10:59:58 -0700 Subject: [PATCH 2/5] Fix Name field's + button (fixes #1529) --- js/id/ui/preset/localized.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/id/ui/preset/localized.js b/js/id/ui/preset/localized.js index eb39b597b..a396913e0 100644 --- a/js/id/ui/preset/localized.js +++ b/js/id/ui/preset/localized.js @@ -40,6 +40,7 @@ iD.ui.preset.localized = function(field, context) { } function addBlank() { + d3.event.preventDefault(); var data = localizedInputs.selectAll('div.entry').data(); data.push({ lang: '', value: '' }); localizedInputs.call(render, data); From 182849cbe694ea7973ee0c74a614522584a953c8 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 28 May 2013 11:07:28 -0700 Subject: [PATCH 3/5] Make preset field placeholders translatable --- build.js | 11 +++++++++-- data/presets.yaml | 1 + dist/locales/en.json | 3 ++- js/id/presets/field.js | 4 ++++ js/id/ui/preset/input.js | 2 +- js/id/ui/preset/localized.js | 2 +- js/id/ui/preset/textarea.js | 2 +- 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/build.js b/build.js index 8d39da11a..297fd0914 100644 --- a/build.js +++ b/build.js @@ -69,10 +69,17 @@ function generateFields() { validate(file, field, fieldSchema); - translations.fields[id] = {label: field.label}; + var t = translations.fields[id] = { + label: field.label + }; + + if (field.placeholder) { + t.placeholder = field.placeholder; + } + if (field.strings) { for (var i in field.strings) { - translations.fields[id][i] = field.strings[i]; + t[i] = field.strings[i]; } } diff --git a/data/presets.yaml b/data/presets.yaml index a1e404ad4..4a497fe3d 100644 --- a/data/presets.yaml +++ b/data/presets.yaml @@ -211,6 +211,7 @@ en: label: Type website: label: Website + placeholder: "http://example.com/" wetland: label: Type wheelchair: diff --git a/dist/locales/en.json b/dist/locales/en.json index 97939097a..db5f3491a 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -655,7 +655,8 @@ "label": "Type" }, "website": { - "label": "Website" + "label": "Website", + "placeholder": "http://example.com/" }, "wetland": { "label": "Type" diff --git a/js/id/presets/field.js b/js/id/presets/field.js index b6e751324..6e5525627 100644 --- a/js/id/presets/field.js +++ b/js/id/presets/field.js @@ -15,5 +15,9 @@ iD.presets.Field = function(id, field) { return field.t('label', {'default': id}); }; + field.placeholder = function() { + return field.t('placeholder', {'default': field.placeholder}); + }; + return field; }; diff --git a/js/id/ui/preset/input.js b/js/id/ui/preset/input.js index 85846c1b7..eafc818b6 100644 --- a/js/id/ui/preset/input.js +++ b/js/id/ui/preset/input.js @@ -14,7 +14,7 @@ iD.ui.preset.url = function(field) { input.enter().append('input') .attr('type', field.type) .attr('id', 'preset-input-' + field.id) - .attr('placeholder', field.placeholder || ''); + .attr('placeholder', field.placeholder()); input .on('blur', change) diff --git a/js/id/ui/preset/localized.js b/js/id/ui/preset/localized.js index a396913e0..e02678929 100644 --- a/js/id/ui/preset/localized.js +++ b/js/id/ui/preset/localized.js @@ -12,7 +12,7 @@ iD.ui.preset.localized = function(field, context) { .attr('type', 'text') .attr('id', 'preset-input-' + field.id) .attr('class', 'localized-main') - .attr('placeholder', field.placeholder || ''); + .attr('placeholder', field.placeholder()); input .on('blur', change) diff --git a/js/id/ui/preset/textarea.js b/js/id/ui/preset/textarea.js index 0fd78955d..e94ad9823 100644 --- a/js/id/ui/preset/textarea.js +++ b/js/id/ui/preset/textarea.js @@ -9,7 +9,7 @@ iD.ui.preset.textarea = function(field) { input.enter().append('textarea') .attr('id', 'preset-input-' + field.id) - .attr('placeholder', field.placeholder || '') + .attr('placeholder', field.placeholder()) .attr('maxlength', 255); input From e913d564d9d2aa5460ea17a6e349be284bb9b406 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 28 May 2013 11:29:31 -0700 Subject: [PATCH 4/5] Fix field placeholders --- js/id/presets/field.js | 3 ++- js/lib/locale.js | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/js/id/presets/field.js b/js/id/presets/field.js index 6e5525627..afbb9f4cb 100644 --- a/js/id/presets/field.js +++ b/js/id/presets/field.js @@ -15,8 +15,9 @@ iD.presets.Field = function(id, field) { return field.t('label', {'default': id}); }; + var placeholder = field.placeholder; field.placeholder = function() { - return field.t('placeholder', {'default': field.placeholder}); + return field.t('placeholder', {'default': placeholder}); }; return field; diff --git a/js/lib/locale.js b/js/lib/locale.js index 4635a06e5..6813fbc6d 100644 --- a/js/lib/locale.js +++ b/js/lib/locale.js @@ -19,10 +19,21 @@ function t(s, o, loc) { if (o) for (var k in o) rep = rep.replace('{' + k + '}', o[k]); return rep; } else { - var missing = 'Missing translation: ' + s; - if (typeof console !== "undefined") console.error(missing); - if (loc !== 'en') return t(s, o, 'en'); - if (o && 'default' in o) return o['default']; - return missing; + function missing() { + var missing = 'Missing ' + loc + ' translation: ' + s; + if (typeof console !== "undefined") console.error(missing); + return missing; + } + + if (loc !== 'en') { + missing(); + return t(s, o, 'en'); + } + + if (o && 'default' in o) { + return o['default']; + } + + return missing(); } } From d088b39d34a6cc273d865f0195c5f355b5141d17 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 28 May 2013 11:52:05 -0700 Subject: [PATCH 5/5] Fix tests --- test/spec/behavior/hover.js | 4 ++-- test/spec/ui/raw_tag_editor.js | 37 ++++++++++++++-------------------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/test/spec/behavior/hover.js b/test/spec/behavior/hover.js index 88d4feda9..ec6dbd030 100644 --- a/test/spec/behavior/hover.js +++ b/test/spec/behavior/hover.js @@ -64,7 +64,7 @@ describe("iD.behavior.Hover", function() { it("replaces the .hover class with .hover-suppressed", function () { container.append('span').attr('class', 'hover'); - container.call(iD.behavior.Hover().altDisables(true)); + container.call(iD.behavior.Hover(context).altDisables(true)); happen.keydown(document, {keyCode: 18}); expect(container.selectAll('.hover')[0]).to.have.length(0); @@ -76,7 +76,7 @@ describe("iD.behavior.Hover", function() { it("replaces the .hover-suppressed class with .hover", function () { container.append('span').attr('class', 'hover-suppressed'); - container.call(iD.behavior.Hover().altDisables(true)); + container.call(iD.behavior.Hover(context).altDisables(true)); happen.keyup(document, {keyCode: 18}); expect(container.selectAll('.hover')[0]).to.have.length(1); diff --git a/test/spec/ui/raw_tag_editor.js b/test/spec/ui/raw_tag_editor.js index 2a7bf500e..f3a049094 100644 --- a/test/spec/ui/raw_tag_editor.js +++ b/test/spec/ui/raw_tag_editor.js @@ -1,38 +1,29 @@ describe('iD.ui.RawTagEditor', function() { var taglist, element, - tags = {highway: 'residential'}, entity, context; - function render() { - taglist = iD.ui.RawTagEditor(context, entity); + function render(tags) { + taglist = iD.ui.RawTagEditor(context) + .entityID(entity.id) + .preset({isFallback: function() { return false; }}) + .tags(tags); + element = d3.select('body') .append('div') .call(taglist); - taglist.tags(entity.tags); } beforeEach(function () { - entity = iD.Entity({type: 'node', id: "n12345", tags: tags}); + entity = iD.Node({id: "n12345"}); context = iD(); - render(); + context.history().merge({n12345: entity}); + render({highway: 'residential'}); }); afterEach(function () { element.remove(); }); - describe("#tags", function () { - it("returns the current tags", function () { - expect(taglist.tags()).to.eql(tags); - }); - - it("returns updated tags when input values have changed", function () { - element.selectAll("input.key").property('value', 'k'); - element.selectAll("input.value").property('value', 'v'); - expect(taglist.tags()).to.eql({k: 'v'}); - }); - }); - it("creates input elements for each key-value pair", function () { expect(element.selectAll("input[value=highway]")).not.to.be.empty; expect(element.selectAll("input[value=residential]")).not.to.be.empty; @@ -40,8 +31,7 @@ describe('iD.ui.RawTagEditor', function() { it("creates a pair of empty input elements if the entity has no tags", function () { element.remove(); - entity = entity.update({tags: {}}); - render(); + render({}); expect(element.select('.tag-list').selectAll("input.value").property('value')).to.be.empty; expect(element.select('.tag-list').selectAll("input.key").property('value')).to.be.empty; }); @@ -52,9 +42,12 @@ describe('iD.ui.RawTagEditor', function() { expect(element.select('.tag-list').selectAll("input")[0][3].value).to.be.empty; }); - it("removes tags when clicking the remove button", function () { + it("removes tags when clicking the remove button", function (done) { + taglist.on('change', function(tags) { + expect(tags).to.eql({highway: undefined}); + done(); + }); element.selectAll("button.remove").trigger('click'); - expect(taglist.tags()).to.eql({}); }); it("adds tags when pressing the TAB key on last input.value", function () {