Escape actions with the escape key

This commit is contained in:
Tom MacWright
2012-11-02 16:32:36 -04:00
parent c27aba6500
commit b9acb41321
2 changed files with 43 additions and 5 deletions
-2
View File
@@ -83,8 +83,6 @@
});
}
for (var a in iD.actions) iD.actions[a].bind();
d3.select('#geocode-form').on('submit', function() {
d3.event.preventDefault();
var val = d3.select('#geocode-location').node().value;
+43 -3
View File
@@ -1,7 +1,8 @@
iD.actions = {};
iD.actions.AddPlace = {
bind: function() {
bind: function(controller) {
this.controller = controller;
d3.selectAll('button#place').on('click', function() {
iD.actions.AddPlace.enter();
});
@@ -19,7 +20,8 @@ iD.actions.AddPlace = {
};
iD.actions.AddRoad = {
bind: function() {
bind: function(controller) {
this.controller = controller;
d3.selectAll('button#road').on('click', function() {
iD.actions.AddRoad.enter();
});
@@ -37,7 +39,8 @@ iD.actions.AddRoad = {
};
iD.actions.AddArea = {
bind: function() {
bind: function(controller) {
this.controller = controller;
d3.selectAll('button#area').on('click', function() {
iD.actions.AddArea.enter();
});
@@ -53,3 +56,40 @@ iD.actions.AddArea = {
d3.selectAll('button#area').classed('active', false);
}
};
iD.actions.Move = {
bind: function(controller) {
this.controller = controller;
},
enter: function() {
d3.selectAll('button').classed('active', false);
},
exit: function() { }
};
iD.controller = (function() {
var controller = {},
action;
for (var a in iD.actions) iD.actions[a].bind(controller);
controller.go = function(x) {
if (action) {
action.exit();
}
x.enter();
action = x;
};
controller.go(iD.actions.Move);
// Pressing 'escape' should exit any action.
d3.select(document).on('keydown', function() {
if (d3.event.keyCode === 27) {
iD.controller.go(iD.actions.Move);
}
});
return controller;
})();