mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-25 06:55:46 +00:00
Remove context dependency from Connection
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
iD.Connection = function(context, options) {
|
||||
iD.Connection = function(options) {
|
||||
|
||||
var event = d3.dispatch('auth', 'loading', 'load', 'loaded'),
|
||||
var event = d3.dispatch('authenticating', 'authenticated', 'auth', 'loading', 'load', 'loaded'),
|
||||
url = options.url || 'http://www.openstreetmap.org',
|
||||
connection = {},
|
||||
user = {},
|
||||
inflight = {},
|
||||
loadedTiles = {},
|
||||
loadingModal,
|
||||
oauth = osmAuth(_.extend({
|
||||
loading: authLoading,
|
||||
done: authDone
|
||||
loading: authenticating,
|
||||
done: authenticated
|
||||
}, options)),
|
||||
ndStr = 'nd',
|
||||
tagStr = 'tag',
|
||||
@@ -38,16 +37,12 @@ iD.Connection = function(context, options) {
|
||||
return d3.xml(url).get().on('load', done);
|
||||
};
|
||||
|
||||
function authLoading() {
|
||||
loadingModal = iD.ui.Loading(context)
|
||||
.message(t('loading_auth'));
|
||||
|
||||
context.container()
|
||||
.call(loadingModal);
|
||||
function authenticating() {
|
||||
event.authenticating();
|
||||
}
|
||||
|
||||
function authDone() {
|
||||
if (loadingModal) loadingModal.close();
|
||||
function authenticated() {
|
||||
event.authenticated();
|
||||
}
|
||||
|
||||
function getNodes(obj) {
|
||||
@@ -321,8 +316,8 @@ iD.Connection = function(context, options) {
|
||||
connection.switch = function(options) {
|
||||
url = options.url;
|
||||
oauth.options(_.extend({
|
||||
loading: authLoading,
|
||||
done: authDone
|
||||
loading: authenticating,
|
||||
done: authenticated
|
||||
}, options));
|
||||
event.auth();
|
||||
connection.flush();
|
||||
|
||||
@@ -23,7 +23,7 @@ window.iD = function () {
|
||||
container,
|
||||
ui = iD.ui(context),
|
||||
map = iD.Map(context),
|
||||
connection = iD.Connection(context, iD.data.keys[0]);
|
||||
connection = iD.Connection(iD.data.keys[0]);
|
||||
|
||||
connection.on('load.context', function loadContext(err, result) {
|
||||
history.merge(result);
|
||||
|
||||
11
js/id/ui.js
11
js/id/ui.js
@@ -145,6 +145,17 @@ iD.ui = function(context) {
|
||||
.call(iD.ui.Splash(context))
|
||||
.call(iD.ui.Restore(context));
|
||||
|
||||
var authenticating = iD.ui.Loading(context)
|
||||
.message(t('loading_auth'));
|
||||
|
||||
context.connection()
|
||||
.on('authenticating.ui', function() {
|
||||
context.container()
|
||||
.call(authenticating);
|
||||
})
|
||||
.on('authenticated.ui', function() {
|
||||
authenticating.close();
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
describe('iD.Connection', function () {
|
||||
var c, context;
|
||||
var c;
|
||||
|
||||
beforeEach(function () {
|
||||
context = iD();
|
||||
c = new iD.Connection(context, {});
|
||||
c = new iD.Connection({});
|
||||
});
|
||||
|
||||
it('is instantiated', function () {
|
||||
|
||||
Reference in New Issue
Block a user