Namespace UI components

This commit is contained in:
Tom MacWright
2013-01-14 14:00:51 -05:00
parent a9bf2f1606
commit 72afc6dcb9
25 changed files with 49 additions and 45 deletions

View File

@@ -41,6 +41,7 @@ all: \
js/id/renderer/*.js \
js/id/svg.js \
js/id/svg/*.js \
js/id/ui.js \
js/id/ui/*.js \
js/id/end.js

View File

@@ -46,6 +46,7 @@
<script src="js/id/svg/tag_classes.js"></script>
<script src="js/id/svg/vertices.js"></script>
<script src="js/id/ui.js"></script>
<script src='js/id/ui/inspector.js'></script>
<script src='js/id/ui/modal.js'></script>
<script src='js/id/ui/confirm.js'></script>

View File

@@ -46,13 +46,13 @@ window.iD = function(container) {
}
}
notice = iD.notice(bar
notice = iD.ui.notice(bar
.append('div')
.attr('class', 'notice'));
map.on('move.disable-buttons', disableTooHigh)
.on('move.contributors', _.debounce(function() {
contributors.call(iD.contributors(map));
contributors.call(iD.ui.contributors(map));
}, 1000));
buttons.append('span')
@@ -96,7 +96,7 @@ window.iD = function(container) {
var save_button = bar.append('button')
.attr('class', 'save action wide')
.call(iD.save().map(map));
.call(iD.ui.save().map(map));
history.on('change.warn-unload', function() {
var changes = history.changes(),
@@ -129,14 +129,14 @@ window.iD = function(container) {
if (navigator.geolocation) {
container.append('div')
.call(iD.geolocate(map));
.call(iD.ui.geolocate(map));
}
var gc = container.append('div').attr('class', 'geocode-control map-control')
.call(iD.geocoder().map(map));
.call(iD.ui.geocoder().map(map));
container.append('div').attr('class', 'map-control layerswitcher-control')
.call(iD.layerswitcher(map));
.call(iD.ui.layerswitcher(map));
container.append('div')
.attr('class', 'inspector-wrap fillL')
@@ -209,7 +209,7 @@ window.iD = function(container) {
.center([-77.02271,38.90085]);
}
d3.select('.user-container').call(iD.userpanel(connection)
d3.select('.user-container').call(iD.ui.userpanel(connection)
.on('logout', connection.logout)
.on('login', connection.authenticate));

View File

@@ -5,7 +5,7 @@ iD.modes.Select = function (entity) {
entity: entity
};
var inspector = iD.Inspector(),
var inspector = iD.ui.inspector(),
behaviors;
function remove() {

View File

@@ -67,7 +67,7 @@ iD.OAuth = function() {
o.oauth_signature = ohauth.signature(oauth_secret, '',
ohauth.baseString('POST', url, o));
var l = iD.loading('contacting openstreetmap...');
var l = iD.ui.loading('contacting openstreetmap...');
// it would make more sense to have this code within the callback
// to oauth.xhr below. however, it needs to be directly within a
@@ -116,7 +116,7 @@ iD.OAuth = function() {
var request_token_secret = token('oauth_request_token_secret');
o.oauth_signature = ohauth.signature(oauth_secret, request_token_secret,
ohauth.baseString('POST', url, o));
var l = iD.loading('contacting openstreetmap...');
var l = iD.ui.loading('contacting openstreetmap...');
function accessTokenDone(err, xhr) {
if (err) callback(err);

1
js/id/ui.js Normal file
View File

@@ -0,0 +1 @@
iD.ui = {};

View File

@@ -1,6 +1,6 @@
iD.commit = function() {
iD.ui.commit = function() {
var event = d3.dispatch('cancel', 'save');
function zipSame(d) {
var c = [], n = -1;
for (var i = 0; i < d.length; i++) {

View File

@@ -1,5 +1,5 @@
iD.confirm = function() {
var modal = iD.modal();
iD.ui.confirm = function() {
var modal = iD.ui.modal();
modal.select('.modal').classed('modal-alert', true);
modal.select('.content')
.classed('modal-section', true)

View File

@@ -1,4 +1,4 @@
iD.contributors = function(map) {
iD.ui.contributors = function(map) {
function contributors(selection) {

View File

@@ -1,5 +1,5 @@
iD.flash = function() {
var modal = iD.modal();
iD.ui.flash = function() {
var modal = iD.ui.modal();
modal.select('.modal').classed('modal-alert', true);

View File

@@ -1,4 +1,4 @@
iD.geocoder = function() {
iD.ui.geocoder = function() {
var map;
@@ -11,7 +11,7 @@ iD.geocoder = function() {
if (err) return hide();
hide();
if (!resp.results.length) {
return iD.flash()
return iD.ui.flash()
.select('.content')
.text('No location found for "' + resp.query[0] + '"');
}

View File

@@ -1,4 +1,4 @@
iD.geolocate = function(map) {
iD.ui.geolocate = function(map) {
function success(position) {
map.center([position.coords.longitude, position.coords.latitude]);

View File

@@ -1,4 +1,4 @@
iD.Inspector = function() {
iD.ui.inspector = function() {
var event = d3.dispatch('changeTags', 'changeWayDirection',
'update', 'remove', 'close', 'splitWay'),
taginfo = iD.taginfo(),
@@ -155,12 +155,12 @@ iD.Inspector = function() {
if (en.on_way) types.push('line');
en.types = types;
console.log(en);
iD.modal()
iD.ui.modal()
.select('.content')
.datum(en)
.call(iD.tagReference);
.call(iD.ui.tagReference);
} else {
iD.flash()
iD.ui.flash()
.select('.content')
.text('This is no documentation available for this tag combination');
}
@@ -168,7 +168,7 @@ iD.Inspector = function() {
} else if (d.key) {
taginfo.values(params, function(err, values) {
if (values.data.length) {
iD.modal()
iD.ui.modal()
.select('.content')
.datum({
data: values.data,
@@ -177,7 +177,7 @@ iD.Inspector = function() {
})
.call(iD.keyReference);
} else {
iD.flash()
iD.ui.flash()
.select('.content')
.text('This is no documentation available for this key');
}

View File

@@ -1,4 +1,4 @@
iD.keyReference = function(selection) {
iD.ui.keyReference = function(selection) {
selection.each(function() {
var selection = d3.select(this),

View File

@@ -1,4 +1,4 @@
iD.layerswitcher = function(map) {
iD.ui.layerswitcher = function(map) {
var event = d3.dispatch('cancel', 'save'),
sources = [{
name: 'Bing',

View File

@@ -1,5 +1,5 @@
iD.loading = function(message) {
var modal = iD.modal();
iD.ui.loading = function(message) {
var modal = iD.ui.modal();
var loadertext = modal.select('.content')
.classed('loading-modal', true)

View File

@@ -1,4 +1,4 @@
iD.modal = function() {
iD.ui.modal = function() {
var animate = d3.select('div.modal').empty();
d3.select('div.modal').transition()

View File

@@ -1,4 +1,4 @@
iD.notice = function(selection) {
iD.ui.notice = function(selection) {
var message = '',
notice = {};

View File

@@ -1,4 +1,4 @@
iD.save = function() {
iD.ui.save = function() {
var map;
@@ -16,7 +16,7 @@ iD.save = function() {
function commit(e) {
d3.select('.shaded').remove();
var l = iD.loading('Uploading changes to OpenStreetMap.');
var l = iD.ui.loading('Uploading changes to OpenStreetMap.');
connection.putChangeset(history.changes(), e.comment, history.imagery_used(), function(err, changeset_id) {
l.remove();
history.reset();
@@ -28,14 +28,14 @@ iD.save = function() {
.text('An error occurred while trying to save');
desc.append('p').text(err.responseText);
} else {
var modal = iD.modal();
var modal = iD.ui.modal();
modal.select('.content')
.classed('success-modal', true)
.datum({
id: changeset_id,
comment: e.comment
})
.call(iD.success()
.call(iD.ui.success()
.on('cancel', function() {
modal.remove();
}));
@@ -49,13 +49,13 @@ iD.save = function() {
if (has_changes) {
connection.authenticate(function(err) {
var modal = iD.modal();
var modal = iD.ui.modal();
var changes = history.changes();
changes.connection = connection;
modal.select('.content')
.classed('commit-modal', true)
.datum(changes)
.call(iD.commit()
.call(iD.ui.commit()
.on('cancel', function() {
modal.remove();
})

View File

@@ -1,4 +1,4 @@
iD.success = function() {
iD.ui.success = function() {
var event = d3.dispatch('cancel', 'save');
function success(selection) {

View File

@@ -1,4 +1,4 @@
iD.tagReference = function(selection) {
iD.ui.tagReference = function(selection) {
selection.each(function() {
function g(x) { return function(d) { return d[x]; }; }
var selection = d3.select(this);

View File

@@ -1,4 +1,4 @@
iD.userpanel = function(connection) {
iD.ui.userpanel = function(connection) {
var event = d3.dispatch('logout', 'login');
function user(selection) {

View File

@@ -48,6 +48,7 @@
<script src="../js/id/svg/tag_classes.js"></script>
<script src="../js/id/svg/vertices.js"></script>
<script src='../js/id/ui.js'></script>
<script src='../js/id/ui/inspector.js'></script>
<script src='../js/id/ui/commit.js'></script>
<script src='../js/id/ui/loading.js'></script>

View File

@@ -1,6 +1,6 @@
describe("Geocoder", function () {
describe("iD.ui.geocoder", function () {
it('can be instantiated', function () {
var geocoder = iD.geocoder();
var geocoder = iD.ui.geocoder();
expect(geocoder).to.be.ok;
});
});

View File

@@ -1,10 +1,10 @@
describe("iD.Inspector", function () {
describe("iD.ui.inspector", function () {
var inspector, element,
tags = {highway: 'residential'},
entity;
function render() {
inspector = iD.Inspector();
inspector = iD.ui.inspector();
element = d3.select('body')
.append('div')
.attr('id', 'inspector-wrap')