Merge controller into iD

This commit is contained in:
John Firebaugh
2013-02-01 11:46:46 -05:00
parent 000ceb6467
commit a78aeeb625
7 changed files with 25 additions and 36 deletions
-1
View File
@@ -41,7 +41,6 @@ all: \
js/id/modes/*.js \
js/id/operations.js \
js/id/operations/*.js \
js/id/controller.js \
js/id/graph/*.js \
js/id/renderer/*.js \
js/id/svg.js \
-1
View File
@@ -123,7 +123,6 @@
<script src='js/id/graph/way.js'></script>
<script src='js/id/connection.js'></script>
<script src='js/id/controller.js'></script>
<script src='js/id/validate.js'></script>
<script src='locale/locale.js'></script>
+1 -1
View File
@@ -48,7 +48,7 @@ iD.behavior.Hash = function(context) {
context.enter(iD.modes.Select([id]));
});
context.controller().on('enter.hash', function() {
context.on('enter.hash', function() {
if (context.mode().id !== 'browse') selectoff();
});
}
-19
View File
@@ -1,19 +0,0 @@
// A controller holds a single action at a time and calls `.enter` and `.exit`
// to bind and unbind actions.
iD.Controller = function() {
var event = d3.dispatch('enter', 'exit');
var controller = { mode: null };
controller.enter = function(mode) {
if (controller.mode) {
controller.mode.exit();
event.exit(controller.mode);
}
mode.enter();
controller.mode = mode;
event.enter(mode);
};
return d3.rebind(controller, event, 'on');
};
+17 -5
View File
@@ -2,7 +2,8 @@ window.iD = function () {
var context = {},
history = iD.History(),
connection = iD.Connection().version(iD.version),
controller = iD.Controller(),
dispatch = d3.dispatch('enter', 'exit'),
mode,
container,
ui = iD.ui(context),
map = iD.Map().connection(connection).history(history);
@@ -11,7 +12,6 @@ window.iD = function () {
context.ui = function () { return ui; };
context.connection = function () { return connection; };
context.history = function () { return history; };
context.controller = function () { return controller; };
context.map = function () { return map; };
/* History delegation. */
@@ -26,8 +26,20 @@ window.iD = function () {
context.entity = function (id) { return history.graph().entity(id); };
context.geometry = function (id) { return context.entity(id).geometry(history.graph()); };
context.enter = controller.enter;
context.mode = function () { return controller.mode; };
context.enter = function(newMode) {
if (mode) {
mode.exit();
dispatch.exit(mode);
}
mode = newMode;
mode.enter();
dispatch.enter(mode);
};
context.mode = function() {
return mode;
};
context.install = function (behavior) { context.surface().call(behavior); };
context.uninstall = function (behavior) { context.surface().call(behavior.off); };
@@ -46,7 +58,7 @@ window.iD = function () {
context.background()
.source(iD.BackgroundSource.Bing);
return context;
return d3.rebind(context, dispatch, 'on');
};
iD.version = '0.0.0-alpha1';
+7 -8
View File
@@ -4,8 +4,7 @@ iD.ui = function (context) {
var connection = context.connection(),
history = context.history(),
map = context.map(),
controller = context.controller();
map = context.map();
if (!iD.supported()) {
container.html('This editor is supported in Firefox, Chrome, Safari, Opera, ' +
@@ -48,7 +47,7 @@ iD.ui = function (context) {
.attr('data-original-title', function (mode) {
return hintprefix(mode.key, mode.description);
})
.on('click.editor', function (mode) { controller.enter(mode); });
.on('click.editor', function (mode) { context.enter(mode); });
function disableTooHigh() {
if (map.editable()) {
@@ -57,7 +56,7 @@ iD.ui = function (context) {
} else {
buttons.attr('disabled', 'disabled');
notice.message(true);
controller.enter(iD.modes.Browse(context));
context.enter(iD.modes.Browse(context));
}
}
@@ -77,12 +76,12 @@ iD.ui = function (context) {
buttons.append('span').attr('class', 'label').text(function (mode) { return mode.title; });
controller.on('enter.editor', function (entered) {
context.on('enter.editor', function (entered) {
buttons.classed('active', function (mode) { return entered.button === mode.button; });
container.classed("mode-" + entered.id, true);
});
controller.on('exit.editor', function (exited) {
context.on('exit.editor', function (exited) {
container.classed("mode-" + exited.id, false);
});
@@ -228,7 +227,7 @@ iD.ui = function (context) {
.on('⌫', function() { d3.event.preventDefault(); });
modes.forEach(function(m) {
keybinding.on(m.key, function() { if (map.editable()) controller.enter(m); });
keybinding.on(m.key, function() { if (map.editable()) context.enter(m); });
});
d3.select(document)
@@ -246,7 +245,7 @@ iD.ui = function (context) {
.on('logout.editor', connection.logout)
.on('login.editor', connection.authenticate));
controller.enter(iD.modes.Browse(context));
context.enter(iD.modes.Browse(context));
if (!localStorage.sawSplash) {
iD.ui.splash();
-1
View File
@@ -119,7 +119,6 @@
<script src='../js/id/graph/way.js'></script>
<script src='../js/id/connection.js'></script>
<script src='../js/id/controller.js'></script>
<script src='../locale/locale.js'></script>
<script src='../locale/en.js'></script>